This is the article on the 18th day of dots girls Advent Calendar 2015.
Nice to meet you, this is 373_mina_mi. Qiita's first post suddenly got quite nervous on the Advent calendar. But write something to rllllho! !! I was told, so I will do my best to write it. ~~ It's too sloppy, but it's all because of Mr. rllllho who introduced me! ~~
With that said, it's a great article for anyone who earnestly raises the points that were caught when Python de amateurs created the development environment and moved the sample code in 3 days (actual work time 10h). I hope the person who gets caught with the same error will be saved ...
Basically Information gathering from Twitter with Python (Environment construction) Gathering information from Twitter with Python (Twitter API) I referred to the page of. Perhaps you can usually do it quickly with just that reference page ...
The error location and error details are difficult to see, so I summarized them later.
Does OpenSSL not work with Python 2.7.6 when an error occurs? I found a typical sentence, so I put it back in. I tried it later and it worked on 2.7.6, so I don't think it's necessary here.
Beforehand
#Install OpenSSL
$sudo apt-get install libssl-dev
#install zlib
$ sudo apt-get install zlib1g-dev
Build from the source file with the necessary items in
$sudo wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz
$tar xvzf Python-2.7.9.tgz
$cd Python-2.7.9
$./configure --prefix=/opt/python2.7.9 --enable-unicode=ucs4 --with-zlib --with-ensurepip=install
$make
$sudo make install
This completes the installation.
$ /opt/python2.7.9/bin/python -V
Python 2.7.9
Also, I confirmed that Python 2.7.9 was installed properly!
Install virtualenv
sudo apt-get install python-dev python-virtualenv
This time, I created a twi-py directory directly under my home directory and built a Python 2.7.9 environment. If you execute it obediently as it is, an error will occur.
$sudo easy_install virtualenv==1.10.1
After running
$virtualenv --python=/opt/python2.7.9/bin/python twi-py
To switch the Python environment, move to the created twi-py and then
$ source bin/activate
Now if the prompt says (twi-py)
, it's OK.
If you check the Python version in this state, it should be 2.7.9!
With the above module installed Gathering information from Twitter with Python (Twitter API) I will omit it because it goes quickly on the street. If you don't enter, the error festival will be at the bottom ...
Gathering information from Twitter with Python (Twitter API) Because it goes quickly on the street, ry I searched for `` dots. Women's Club''
(twi-py)***@***-VirtualBox:~/twi-py$ python twi-sample1.py
tweet_id: 676300237133090817
created_at: Mon Dec 14 07:18:36 +0000 2015
user_id: 1703590964
user_desc: 「dots.Is an engineer study session information service that allows you to search for study sessions with the content you are interested in whenever and wherever you want to know.
screen_name: eventdots
user_name: eventdots
For the time being, dots. Seems to have been caught. I'd like to understand the parameters properly and try various things again, but this time I'm here for the time being! This was the limit to make it in time for the Advent Calender _ (: 3 ”∠) _
so. It took three days to expose the cause that finally moved the sample. I can't deny anyone's advantage, but I'm sure there are people in the world who will encounter the same error ...! !!
"Just install VirtualBox and put Ubuntu on it" When I thought about it, the first thing that caught me was the screen resolution.
For some reason, the screen size cannot be changed from 640 x 480. The result How to change the screen size (resolution) of Ubuntu installed in VirtualBox to something other than 640x480 I found it and solved it safely by doing this street.
virtualenv --python=/opt/python2.7.9/bin/python twi-py
When I try, I get an error.
***@***VirtualBox:~$ virtualenv --python=/opt/python2.7.9/bin/python twi-py
Running virtualenv with interpreter /opt/python2.7.9/bin/python
New python executable in twi-py/bin/python
Installing setuptools, pip...
Complete output from command /home/Home directory/twi-py/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/share/python-virtualenv/pip-1.5debian1-py2.py3-none-any.whl/pip/__init__.py", line 10, in <module>
File "/usr/share/python-virtualenv/pip-1.5debian1-py2.py3-none-any.whl/pip/util.py", line 18, in <module>
File "/usr/share/python-virtualenv/pip-1.5debian1-py2.py3-none-any.whl/pip/_vendor/distlib/version.py", line 14, in <module>
File "/usr/share/python-virtualenv/pip-1.5debian1-py2.py3-none-any.whl/pip/_vendor/distlib/compat.py", line 31, in <module>
ImportError: cannot import name HTTPSHandler
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 2339, in <module>
main()
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 825, in main
symlink=options.symlink)
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 993, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 961, in install_wheel
'PIP_NO_INDEX': '1'
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 903, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /home/Home directory/twi-py/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1
As conclusion [[Error countermeasures] OS Error: Command ・ ・ ・ "import sys, pip; sys ... d "] + sys.argv [1:])) "setuptools pip failed with error code 1](http: // qiita .com / fantm21 / items / 05946b81df4f7ab35377) As I wrote in the above success example, referring to
$sudo easy_install virtualenv==1.10.1
After executing virtuslenv
, it was built.
I feel like I was angry that I didn't have zlib in the first place, but I forgot the details because I failed to get the log ...
It seems that pip is originally included in Python 2.7.9, but When I try to pip install according to the article I referred to
(twi-py)***@***VirtualBox:~/twi-py$ pip install requests requests_oauthlib
Traceback (most recent call last):
File "/home/Home directory/twi-py/bin/pip", line 9, in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/home/Home directory/twi-py/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/home/Home directory/twi-py/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
return ep.load()
File "/home/Home directory/twi-py/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/home/Home directory/twi-py/lib/python2.7/site-packages/pip/__init__.py", line 10, in <module>
from pip.util import get_installed_distributions, get_prog
File "/home/Home directory/twi-py/lib/python2.7/site-packages/pip/util.py", line 17, in <module>
from pip.vendor.distlib import version
File "/home/Home directory/twi-py/lib/python2.7/site-packages/pip/vendor/distlib/version.py", line 13, in <module>
from .compat import string_types
File "/home/Home directory/twi-py/lib/python2.7/site-packages/pip/vendor/distlib/compat.py", line 31, in <module>
from urllib2 import (Request, urlopen, URLError, HTTPError,
ImportError: cannot import name HTTPSHandler
It seems that pip is not included by default, so I checked Install Python 2.7.9 and Python 3.4.x with pip. Install pip referring to. If you try, this time I was angry without open ssl. Also, when I tried to create an environment with virtualenv, I felt angry that there was no zlib. So, in conclusion Beforehand
#Install OpenSSL
$sudo apt-get install libssl-dev
#install zlib
$ sudo apt-get install zlib1g-dev
Then re-install Python from configure! So, I arrived at the success example I wrote above.
Finally, you can go through pip-install and run the sample! !! The error I encountered when I thought.
(twi-py)***@***VirtualBox:~/twi-py$ python twi-sample1.py
Error code: 401
Traceback (most recent call last):
File "twi-sample1.py", line 63, in <module>
main()
File "twi-sample1.py", line 19, in main
for tweet in tweets["statuses"]:
TypeError: 'NoneType' object has no attribute '__getitem__'
TypeError: 'NoneType' object has no attribute '__getitem__'
?
Is the object type different? But this doesn't seem to be a module error?
~~ * I'm a Python beginner who gets angry at the end of every sentence;
So, the conclusion. It was a copy of the API Key ...
。And after this was discovered and the sample was successfully executed in Python 2.7.9, Maybe ... I thought I would make a virtualenv with Python 2.7.6 in the same way ... It worked as expected. I'm scared of copypemis! !! !! However, I got an error due to SSL or something, so I think it was because I didn't put that area properly with apt-get.
However, it took me more than two days to get Python 2.7.9 into pip, so if I could copy it properly, I felt like I could do something like that in three days, so I'll do my best. I'm depressed. But is it a hobby ...
Recommended Posts