pip failing to install any packages - ssl.py error - python

Whenever I try to install any package from pip (Flask, Github-Flask, Django even upgrading setuptools), I always am faced with this error:
File "/usr/lib/python2.7/socket.py", line 380, in read
data = self._sock.recv(left)
File "/usr/lib/python2.7/httplib.py", line 561, in read
s = self.fp.read(amt)
File "/usr/lib/python2.7/socket.py", line 380, in read
data = self._sock.recv(left)
File "/usr/lib/python2.7/ssl.py", line 241, in recv
return self.read(buflen)
File "/usr/lib/python2.7/ssl.py", line 160, in read
return self._sslobj.read(len)
error: [Errno 104] Connection reset by peer
I am using Kubuntu 12.04, python 2.7. I have already tried reinstalling python2.7 and pip. Any ideas?

Related

Python, can not install pyaudio

I'm trying to install pyaudio in 3 ways but failed:
Solution 1
pip install pyaudio
of course, it's not working but worth a try.
Solution 2
pip install pipwin
pipwin install pyaudio
and this is what I got:
Traceback (most recent call last):
File "C:\Users\Admin\python\Python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\Admin\python\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Admin\virtualenv\ErzaProject\Scripts\pipwin.exe\__main__.py", line 7, in <module>
File "C:\Users\Admin\virtualenv\ErzaProject\lib\site-packages\pipwin\command.py", line 98, in main
cache.install(package)
File "C:\Users\Admin\virtualenv\ErzaProject\lib\site-packages\pipwin\pipwin.py", line 300, in install
wheel_file = self.download(requirement)
File "C:\Users\Admin\virtualenv\ErzaProject\lib\site-packages\pipwin\pipwin.py", line 294, in download
return self._download(requirement, dest)
File "C:\Users\Admin\virtualenv\ErzaProject\lib\site-packages\pipwin\pipwin.py", line 290, in _download
obj.start()
File "C:\Users\Admin\virtualenv\ErzaProject\lib\site-packages\pySmartDL\pySmartDL.py", line 267, in start
urlObj = urllib.request.urlopen(req, timeout=self.timeout, context=self.context)
File "C:\Users\Admin\python\Python37\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\Admin\python\Python37\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "C:\Users\Admin\python\Python37\lib\urllib\request.py", line 543, in _open
'_open', req)
File "C:\Users\Admin\python\Python37\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "C:\Users\Admin\python\Python37\lib\urllib\request.py", line 1360, in https_open
context=self._context, check_hostname=self._check_hostname)
File "C:\Users\Admin\python\Python37\lib\urllib\request.py", line 1319, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error timed out>
Solution 3
pip install PyAudio-0.2.11-cp36-cp36m-win_amd64.whl
and the result:
WARNING: Requirement 'PyAudio-0.2.11-cp36-cp36m-win_amd64.whl' looks like a filename, but the file does not exist
ERROR: PyAudio-0.2.11-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform.
I even go to this page directly and got “ERR_CONNECTION_TIMED_OUT” error when clicking on the file.
I just wonder if there is any problem with the main page? Or it's because of my system? And any way to install pyaudio?
(I'm currently on win10 64bit)
Looking at the pypi files page for PyAudio, the latest wheels are for Python 3.6.
From your traceback it seems like you are running Python 3.7, so that won't work. The link on the pythonlibs page also times out for me.
If pip cannot find a suitable wheel, it will try to compile the package using its setup.py.
Nothing for it but to set up a development environment and compile it yourself. This link might help with that.

Python 3 virtual environment uses default Python's (2.6) socket connections for PyMySQL

A server's default Python version is 2.6. Python 3 is also installed and I created a virtual environment (python3 -m venv py3env) and installed Flask and PyMySQL within the virtual environment.
However, after the web-server (Apache+WSGI) is configured, the application doesn't work and throws the following error:
File "/var/www/webapp/py3env/lib/python3.6/site-packages/pymysql/__init__.py", line 90, in Connect
return Connection(*args, **kwargs)
File "/var/www/webapp/py3env/lib/python3.6/site-packages/pymysql/connections.py", line 699, in __init__
self.connect()
File "/var/www/webapp/py3env/lib/python3.6/site-packages/pymysql/connections.py", line 935, in connect
self._get_server_information()
File "/var/www/webapp/py3env/lib/python3.6/site-packages/pymysql/connections.py", line 1249, in _get_server_information
packet = self._read_packet()
File "/var/www/webapp/py3env/lib/python3.6/site-packages/pymysql/connections.py", line 991, in _read_packet
packet_header = self._read_bytes(4)
File "/var/www/webapp/py3env/lib/python3.6/site-packages/pymysql/connections.py", line 1025, in _read_bytes
data = self._rfile.read(num_bytes)
File "/usr/lib64/python2.6/io.py", line 940, in read
return self._read_unlocked(n)
File "/usr/lib64/python2.6/io.py", line 974, in _read_unlocked
chunk = self.raw.read(wanted)
File "/usr/lib64/python2.6/io.py", line 591, in read
n = self.readinto(b)
File "/var/www/webapp/py3env/lib/python3.6/site-packages/pymysql/_socketio.py", line 59, in readinto
return self._sock.recv_into(b)
TypeError: recv_into() argument 1 must be pinned buffer, not bytearray
I tried installing python-socketio via pip but it still isn't being used.
MySQL-python is installed on the server.
How does one force the application to use the Virtual environment's version?

AttributeError: decoding error while running Python tweepy script in Ubuntu

I have a Python 3.5 script which essentially is a Twitter scraper that collects tweets using the tweepy package and its StreamListener function.
Now my script runs perfectly within the Command shell but when I try to run it on the Ubuntu environment of my server I receive a decoding error.
File "/usr/lib/python3/dist-packages/tweepy/streaming.py", line 445, in filter
self._start(async)
File "/usr/lib/python3/dist-packages/tweepy/streaming.py", line 361, in _start
self._run()
File "/usr/lib/python3/dist-packages/tweepy/streaming.py", line 294, in _run
raise exception
File "/usr/lib/python3/dist-packages/tweepy/streaming.py", line 247, in _run
verify=self.verify)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 454, in reque st
prep = self.prepare_request(req)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 388, in prepa
re_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/usr/lib/python3/dist-packages/requests/models.py", line 297, in prepare
self.prepare_auth(auth, url)
File "/usr/lib/python3/dist-packages/requests/models.py", line 490, in prepare _auth
r = auth(self)
File "/usr/lib/python3/dist-packages/requests_oauthlib/oauth1_auth.py", line 7 1, in __call__
r.url = to_native_str(r.url)
File "/usr/lib/python3/dist-packages/requests_oauthlib/oauth1_auth.py", line 1 4, in to_native_str
return string.decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'
This makes sense because you can't decode a string which already is a string. But my question is how I can solve this issue because this is an error occuring within a package?
It looks like the problem comes from requests-oauthlib, you are running an old version of it, and the problem seems to have been fixed since 4.0.1 .
Upgrade your system (the packaged version with Ubuntu 16.10 is 7.0):
sudo apt update && apt upgrade
Or install using pip:
sudo pip3 install requests-oauthlib

Pip install from requirements file is failing, but installing one by one works

I am trying to install a bunch of python dependencies using a requirements.txt file with the following command:
pip install -r requirements.txt
The requirements.txt file has the following packages:
pep8
selenium
paramiko
soappy
nose
wmi
mock
python-keystoneclient
python-novaclient
python-cinderclient
python-swiftclient
python-glanceclient
python-heatclient
python-neutronclient
But when running the pip install command I am getting this error:
Downloading/unpacking PrettyTable>=0.7,<0.8 (from python-keystoneclient->-r requ
irements.txt (line 9))
Cleaning up...
Exception:
Traceback (most recent call last):
File "C:\Python27\VirtualEnvs\test\lib\site-packages\pip\basecommand.py", line
122, in main
status = self.run(options, args)
File "C:\Python27\VirtualEnvs\test\lib\site-packages\pip\commands\install.py",
line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundl
e=self.bundle)
File "C:\Python27\VirtualEnvs\test\lib\site-packages\pip\req.py", line 1197, i
n prepare_files
do_download,
File "C:\Python27\VirtualEnvs\test\lib\site-packages\pip\req.py", line 1375, i
n unpack_url
self.session,
File "C:\Python27\VirtualEnvs\test\lib\site-packages\pip\download.py", line 54
6, in unpack_http_url
resp = session.get(target_url, stream=True)
File "C:\Python27\VirtualEnvs\test\lib\site-packages\pip\_vendor\requests\sess
ions.py", line 395, in get
return self.request('GET', url, **kwargs)
File "C:\Python27\VirtualEnvs\test\lib\site-packages\pip\download.py", line 23
7, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "C:\Python27\VirtualEnvs\test\lib\site-packages\pip\_vendor\requests\sess
ions.py", line 383, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\VirtualEnvs\test\lib\site-packages\pip\_vendor\requests\sess
ions.py", line 486, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\VirtualEnvs\test\lib\site-packages\pip\_vendor\requests\adap
ters.py", line 381, in send
raise ProxyError(e)
ProxyError: Cannot connect to proxy. Socket error: [Errno 10054] An existing con
nection was forcibly closed by the remote host.
Storing debug log for failure in C:\Users\cjmarti2\pip\pip.log
But for some reason if I install all packages using pip install <package> they all get installed correctly.
A couple of things to consider;
1) since I am in my company's intranet I am setting a proxy using set https_proxy=https://company-proxy.com:port. 2) Installing the exact same packages using requirements.txt in a Linux machine works fine. Any ideas?
Update:
I was using Python 2.7 for 64 bits. I uninstalled it and installed the 32 bits, and I no longer had this problem. Looks like the python version was the problem, the 64 bits one for some reason cause problems.

pip install django timeout on MacOSX Lion

On a MBP, following instructions (http://techblog.rosedu.org/python-environment.html), I installed Xcode 4.4.1, brew (brew doctor says all set), and then python. Next, I tried to setup virtualenv:
> $MYPYTHON/bin/python distribute_setup.py
> $MYPYTHON/bin/easy_install pip
> $MYPYTHON/bin/pip install virtualenv
I then created a virtual environment and tried to install django:
> $MYPYTHON/bin/virtualenv $MYENV
> $MYENV/bin/pip install Django
It downloads 98% and then hangs for a while, and finally I get a traceback indicating a timeout:
pcm#pcm-mac[302]% $MYENV/bin/pip install django
Downloading/unpacking django
Downloading Django-1.4.1.tar.gz (7.7Mb): 7.5Mb downloaded
Exception:
Traceback (most recent call last):
File "/Users/pcm/Documents/workspace/virtual/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/basecommand.py", line 104, in main
status = self.run(options, args)
File "/Users/pcm/Documents/workspace/virtual/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/commands/install.py", line 245, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/Users/pcm/Documents/workspace/virtual/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/req.py", line 985, in prepare_files
self.unpack_url(url, location, self.is_download)
File "/Users/pcm/Documents/workspace/virtual/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/req.py", line 1109, in unpack_url
retval = unpack_http_url(link, location, self.download_cache, self.download_dir)
File "/Users/pcm/Documents/workspace/virtual/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.py", line 451, in unpack_http_url
download_hash = _download_url(resp, link, temp_location)
File "/Users/pcm/Documents/workspace/virtual/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/download.py", line 368, in _download_url
chunk = resp.read(4096)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 380, in read
data = self._sock.recv(left)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 553, in read
s = self.fp.read(amt)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 380, in read
data = self._sock.recv(left)
timeout: timed out
I see the same thing, if I just run the version of pip from /usr/local/bin/. I tried other packages (selenium, mock) and they downloaded and installed fine.
I'm at a loss as to what I may be doing wrong, or if there is some issue with django installs via pip. Advice?
Use:
pip --default-timeout=60 install django

Categories