Default PIP in python virtual environment is ancient, how to fix it? - python

I used python3 -m venv to create a virtual environment, in that virtual environment my settings are:
python 3.5.2
pip 8.1.1
Mac OS 10.13.6
That pip version is extremely OLD and leads to a problem described below: how do I get venv to install a newer version of pip?
Whenever I run "pip install " I get an error of the form:
Could not fetch URL https://pypi.python.org/simple/<any_package>/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:645) - skipping
I have tried this with = flask, gunicorn, and requests and believe that it's not a package specific problem.
What I tried to fix the problem:
I came across this link which suggested I should upgrade pip somehow: https://github.com/pypa/pip/issues/5226
So I upgraded pip up to the latest version:
pip 20.0.2 from /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip (python 3.5)
But the problem persisted. So then I upgraded venv to the latest version.
But the problem persisted again.
I did some more research online and came across the following github issue: https://github.com/pypa/pip/issues/5363
Which had as part of the problem statement text very similar to my TLS issue, but none of the answers there seemed to be able to fix the problem (pasting each one resulted in the same TLS issue).
Finally I found something that worked:
From this question: Upgrading pip/installing django - [SSL: TLSV1_ALERT_PROTOCOL_VERSION]
The solution below:
curl https://bootstrap.pypa.io/get-pip.py | python3
Upgrades my "virtual enviromnet's pip" to the correct version. But I yet to figure out how to get my default pip (when I create a new virtual environment) to be up to date.

As of today, it is not possible.
Starting with Python 3.9 it should be possible to do something like path/to/pythonX.Y -m venv --upgrade-deps .venv, and that would upgrade pip and setuptools in the newly created virtual environment:
https://bugs.python.org/issue34556
https://github.com/python/cpython/pull/13100
https://docs.python.org/3.9/library/venv.html
You could try virtualenv instead, if it suits your workflow better. As far as I know it tries to always install the latest version of pip in the virtual environments it creates.
https://pypi.org/project/virtualenv/
There is an example of code at the end of venv's documentation showing how to create a tool that downloads and installs up-to-date pip and setuptools:
https://docs.python.org/3/library/venv.html#an-example-of-extending-envbuilder
User wim made an interesting suggestion here:
https://stackoverflow.com/a/60217751
I have a tool called ve that does something similar:
https://pypi.org/project/ve/
There are some answers to similar questions, suggesting to modify the wheel files bundled with ensurepip in Python's standard library, but I wouldn't recommend that.
Similar questions:
How to get "python -m venv" to directly install latest pip version
Why 'python3 -m venv myenv' installs older version of pip into myenv than any version of pip I can find anywhere on the system?

Related

Virtual Environment Being Ignored or Overridden

I have been having an issue where pip and python seem to be ignoring the fact that they are in a virtualenv. I found the following:
pip command in virtualenv ignored in favour of system pip command
pip not pointing to virtual enviroment, in virtual enviroment
But neither seem to answer my issue.
The key issue seems to be when pip is trying to install modules it is detecting the module at the system level and then thinking it is already there, tries to uninstall it then fails because it isn't in the same environment.
For example, I need to update Wernzeug, so I try:
[venv] me#somemachine: pip install werkzeug
which results in:
Requirement already satisfied: werkzeug in /python/3.7.2/rh60_64/modules (0.15.2)
The weird bit starts if I run an uninstall:
[venv] me#somemachine: pip uninstall werkzeug
When I get:
Not uninstalling werkzeug at
/python/3.7.2/rh60_64/modules, outside environment
/venv Can't uninstall 'Werkzeug'. No files were found to uninstall.
Here's the kicker, due to the way the server is built I'm having to use the 'sw' command to get python (in this case 3.7.2). I'm wondering if this has something to do with the venv getting confused with where it is supposed to be looking. I do not have root access to the server, nor am I likely to get it, so I can't mess with the system installed modules.
Other useful info:
The base system is REHL 6.6
pip -V output:
pip 22.0.4 from /venv/lib/python3.7/site-packages/pip (python 3.7)
Any pointers or ideas that might help this are more than welcome.

Gurobi optimizer on python

I need a free optimizer for python. I use PYCharm and python 3.6 (I have python 2.7 on my lap top too)
Now, want to install Gurobi optimizer in PYCharm. but there are some problems:
when I wanted to install "gurobipy" library, the first error was on pip version. It was 9.0.3 and I had to upgrade that to 10.0.1. I've done that successfully and now when I want to install gurobipy, its error again: (AttributeError: module 'pip' has no attribute 'main')
After a quick search, I found that this is a problem of pip 10.0.1
And now I'm really confused. Can anyone help me? I really need this optimizer on python
I see people with the pip 10.0.1 issue downgrading pip version via python -m pip install --upgrade pip==9.0.3. So, how about using the pip 9.0.3 and an older gurobipy (like gurobipy==x.x.x) which might work with the older pip?
EDIT:
How to install gurobipy 8.0.1 for python without conda on Linux
Register an account on the Gurobi official website and login.
Download the latest version from the website.
Extract the package and go to the directory that contains the file setup.py
Run sudo python setup.py install
Add the following lines to your
.bashrc files:
export GUROBI_HOME="/path/to/gurobi801/linux64"
export PATH="${PATH}:${GUROBI_HOME}/bin"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${GUROBI_HOME}/lib"
or to run from PyCharm, you need to set LD_LIBRARY_PATH manually on the app like this
Test with import gurobipy

Module installation in python returning "Could not find any downloads that satisfy the requirement" error?

Unfortunately I cannot install any modules on python 3.4 32 Bit using the pip command due to the following error.
How do I get around the problem. I have removed all other installations of python and have installed the 32 Bit version rather than the 64 Bit one?
Thanks
Edit 1:
At the moment I can't even upgrade pip
Edit 2
Unfortunately it still returns an error.
Try upgrading your pip with
python -m pip install -U pip
If this fails too, it has to be a network problem. See if you're properly connected to internet.
Seems like you might be using an old version of PIP which is facing SSL certification issues and is hence unable to connect. You can do a manual reinstall of pip using these commands.:
python -m pip uninstall pip setuptools
Then, download this script
Finally, run the script with:
python get-pip.py

How to install Numpy & pip3 for python3.x when they were installed in python2.7? Using Conda?

I want to write program in python3 (3.5), hence I installed python3 next to the pre-installed python2 (2.7) on Mac OS X El Captian.
Since my terminal runs python2.7 by default and Numpy is already installed for it, I put alias python=python3 and expected to be able to install Numpy for python3. when I type pip install numpy. This was the generated message:
Requirement already satisfied (use --upgrade to upgrade): numpy in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
I also noticed that I have no pip3 even though I am using python3: python --version returned Python 3.5.2, but pip3 install numpy got me -bash: pip3: command not found.
So my questions are:
1) How to install Numpy for python3.x when Numpy is installed on python2.x?
2) How to get pip3?
3) Is it better to use virtual environments, such as Conda, instead of juggling between python2 and python3 on the system?
Thank you from a total n00b
------------------- Update -------------------
Reinstalling python3 also fixed another problem in my case.
When I ran brew doctor, one of the warning message I got was:
Warning: You have unlinked kegs in your Cellar Leaving kegs unlinked can lead to build-trouble and cause brews that depend on those kegs to fail to run properly once built. Run brew link on these: python –
This is a result of me running brew unlink python in order to fix
"Python quit unexpectedly"
when I launch Vim and also
"The ycmd server SHUT DOWN"
Both seem to relate to the YouCompleteMe autocomplete plugin which I downloaded for Python.
I got my idea of removing symlinks from here and here
However, Homebrew evidently did not like the absence of those 39 symlinks.
After uninstall (brew uninstall python3) and then re-install python3 (brew install python3) as Toby suggested, Homebrew gave me
You can install Python packages with
pip3 install <package>
Then when I pip3 install numpy and pip3 install scipy, both executed successfully.
To my surprise, symlinks created during Python installation used to cause aforementioned error messages for Python and YouCompleteMe, but now I open python files using Vim without crash from a fresh Python installation, which definitely created the symlinks.
------------------- Update2 ------------------
After re-installing Anaconda2, the same YouCompleteMe error came back. I suspect Anaconda messed up symlinks.
I would recommend using the Anaconda Python distribution.
The main reasons are as such:
You will have a Python distribution that comes with numpy and the rest of the Scientific Python stack.
The Anaconda Python will be installed under your home directory, with no need for sudo-ing to install other packages.
conda install [put_packagename_here] works alongside pip install [put_packagename_here]; conda install is much 'cleaner' (IMHO, differing opinions are welcome).
If you have a Python 3 environment as your default, then pip works out-of-the-box without needing to remember to do pip3.
conda environments are easier to manage than virtualenv environments, in my opinion. And yes, you can have Python 2 alongside Python 3.
I once messed up my system Python environment - the one that came with my Mac - and it broke iPhoto (back in the day). Since then, I became convinced of needing separate, atomic environments for different projects.
I've detailed more reasons in a personal blog post.
Other distributions, of course, are all good, provided they give you what you need :).
The simplest way on a Mac is with Homebrew:
http://brew.sh/
Install Homebrew, then run:
brew install python3 pip3
Edit --
Python3 includes pip3, but Homebrew occasionally has trouble linking to the correct versions, depending on what has been installed. Running the following command:
brew doctor
And if you see errors relating to python or unlinked kegs, try running:
brew uninstall python python3
And reinstalling after checking brew doctor.
https://unix.stackexchange.com/questions/233519/pip3-linked-to-python-framework-instead-of-homebrew-usr-local-bin

pip connection failure: cannot fetch index base URL http://pypi.python.org/simple/

I run sudo pip install git-review, and get the following messages:
Downloading/unpacking git-review
Cannot fetch index base URL http://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement git-review
No distributions at all found for git-review
Storing complete log in /home/sai/.pip/pip.log
Does anyone has any idea about this?
I know this is an old thread, but I encountered this issue today and wanted to share my solution to the problem because I haven't seen this solution elsewhere on SO.
My environment: Python 2.7.12/2.7.14 on Ubuntu 12.04.5 LTS in a virtualenv, pip version 1.1.
My Errors:
pip install nose
in console:
Cannot fetch index base URL http://pypi.python.org/simple/
in ~/.pip/pip.log:
Could not fetch URL http://pypi.python.org/simple/: HTTP Error 403: SSL is required
Curious for me because I had been running these same commands in a script without issue for about a year.
this fixed it:
pip install --index-url=https://pypi.python.org/simple/ nose
(note the https)
You need to upgrade your pip installation because it is still using http instead of https.
The --index-url (short version: -i) option allows you to specify an index-url in the call to pip itself, there you can use the https-variant. Then you can instruct pip to upgrade itself.
sudo pip install --index-url https://pypi.python.org/simple/ --upgrade pip
Afterwards you should be able to use pip without the --index-url option.
I believe that the release 7.0.0 (2015-05-21) triggered this issue. The release note for that version states the following:
BACKWARD INCOMPATIBLE No longer implicitly support an insecure origin
origin, and instead require insecure origins be explicitly trusted
with the --trusted-host option.
You can check your pip version with pip --version.
This would mean that issuing sudo pip install --trusted-host --upgrade pip once would also solve this issue, albeit download pip over insecure http. This might also not work at all, because it is possible that the insecure endpoint is no longer accessible on the server (I have not tested this).
EDIT:
The current version of PIP no longer has this issue. As of right now, version: 7.1.2 is the current version. Here is the PIP link:
https://pypi.python.org/pypi/pip
ORIGINAL FIX:
I got this issue when trying to use pip==1.5.4
This is an issue related to PIP and Python's PYPI trusting SSL certificates. If you look in the PIP log in Mac OS X at: /Users/username/.pip/pip.log it will give you more detail.
My workaround to get PIP back up and running after hours of trying different stuff was to go into my site-packages in Python whether it is in a virtualenv or in your normal site-packages, and get rid of the current PIP version. For me I had pip==1.5.4
I deleted the PIP directory and the PIP egg file. Then I ran
easy_install pip==1.2.1
This version of PIP doesn't have the SSL issue, and then I was able to go and run my normal pip install -r requirements.txt within my virtualenv to set up all packages that I wanted that were listed in my requirements.txt file.
This is also the recommended hack to get passed the issue by several people on this Google Group that I found:
https://groups.google.com/forum/#!topic/beagleboard/aSlPCNYcVjw
I added --proxy command line option to point to the proxy and it's working (pip version is 1.5.4 and python 2.7). for some reason it was not taking the shell env variables HTTPS_PROXY, HTTP_PROXY, https_proxy, http_proxy.
sudo pip --proxy [user:passwd#]proxy.server:port install git-review
Check your proxy connection, I had a similar issue, then I changed my connection which wasn't proxied and boom, of it started downloading and setting up the library
I had the same issue with pip 1.5.6.
I just deleted the ~/.pip folder and it worked like a charm.
rm -r ~/.pip/
I had the same problem with pip==1.5.6. I had to correct my system time.
# date -s "2014-12-09 10:09:50"
This worked for me on Ubuntu 12.04.
pip install --index-url=https://pypi.python.org/simple/ -U scikit-learn
If that's not a proxy/network problem you should try to create/edit config file .pip/pip.conf or if you are running pip as root /root/.pip/pip.conf. Check and change index-url from http to https.
It should be like this:
[global]
index-url=https://pypi.python.org/simple/
Worked for me with Ubuntu 12 and pip 9.0.1
it works!
sudo pip --proxy=http://202.194.64.89:8000 install elasticsearch ;
202.194.64.89:8000 is my PROXY,
In my case (Python 3.4, in a virtual environment, running under macOS 10.10.6) I could not even upgrade pip itself. Help came from this SO answer in the form of the following one-liner:
curl https://bootstrap.pypa.io/get-pip.py | python
(If you do not use a virtual environment, you may need sudo python.)
With this I managed to upgrade pip from Version 1.5.6 to Version 10.0.0 (quite a jump!). This version does not use TLS 1.0 or 1.1 which are not supported any more by the Python.org site(s), and can install PyPI packages nicely. No need to specify --index-url=https://pypi.python.org/simple/.
I was able to fix this by upgrading my python, which had previously been attached to an outdated version of OpenSSL. Now it is using 1.0.1h-1 and my package will pip install.
FYI, my log and commands, using anaconda and installing the pytest-ipynb package [1] :
$ conda update python
Fetching package metadata: ....
Solving package specifications: .
Package plan for installation in environment /Users/me/anaconda/envs/py27:
The following NEW packages will be INSTALLED:
openssl: 1.0.1h-1
The following packages will be UPDATED:
python: 2.7.5-3 --> 2.7.8-1
readline: 6.2-1 --> 6.2-2
sqlite: 3.7.13-1 --> 3.8.4.1-0
tk: 8.5.13-1 --> 8.5.15-0
Proceed ([y]/n)? y
Unlinking packages ...
[ COMPLETE ] |#############################################################| 100%
Linking packages ...
[ COMPLETE ] |#############################################################| 100%
$ pip install pytest-ipynb
Downloading/unpacking pytest-ipynb
Downloading pytest-ipynb-0.1.1.tar.gz
Running setup.py (path:/private/var/folders/4f/b8gwyhg905x94twqw2pbklyw0000gn/T/pip_build_me/pytest-ipynb/setup.py) egg_info for package pytest-ipynb
Requirement already satisfied (use --upgrade to upgrade): pytest in /Users/me/anaconda/envs/py27/lib/python2.7/site-packages (from pytest-ipynb)
Installing collected packages: pytest-ipynb
Running setup.py install for pytest-ipynb
Successfully installed pytest-ipynb
Cleaning up...
[1] My ticket about this issue; https://github.com/zonca/pytest-ipynb/issues/1
I faced same problem but that was related proxy. it was resolved by setting proxy.
Set http_proxy=http://myuserid:mypassword#myproxyname:myproxyport
Set https_proxy=http://myuserid:mypassword#myproxyname:myproxyport
This might help someone.
If your proxy is configured correctly, then pip version 1.5.6 will handle this correctly. The bug was resolved.
You can upgrade pip with easy_install pip==1.5.6
Extra answer: if you are doing this from chroot.
You need source of random numbers to be able to establish secure connection to pypi.
On linux, you can bind-mount host dev to chroot dev:
mount --bind /dev /path-to-chroot/dev
I also got this error while installing pyinstaller in a proxied connection. I just connect direct Internet connection(Using my dongle) and did that again.
sudo pip install pyinstaller
This worked for me.
You might be missing a DNS server conf in /etc/resolv.conf
make sure u can ping to:
ping pypi.python.org
if you're not getting a ping try to add a DNS server to file...something like:
nameserver xxx.xxx.xxx.xxx
My explanation/enquiry is for windows environment.
I am pretty new to python, and this is for someone still novice than me.
I installed the latest pip(python installer package) and downloaded 32 bit/64 bit (open source) compatible binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/, and it worked.
Steps followed to install pip, though usually pip is installed by default during python installation from www.python.org/downloads/
- Download pip-7.1.0.tar.gz from https://pypi.python.org/pypi/pip.
- Unzip and un-tar the above file.
- In the pip-7.1.0 folder, run: python setup.py install. This installed pip latest version.
Use pip to install(any feasible operation) binary package.
Run the pip app to do the work(install file), as below:
\python27\scripts\pip2.7.exe install file_path\file_name --proxy
If you face, wheel(i.e egg) issue, use the compatible binary package file.
Hope this helps.
in my case I would install django (
pip install django
)
and it has a same problem with ssl certificate (Cannot fetch index base URL http://pypi.python.org/simple/ )
it's from virtualenv so DO :
FIRST:
delete your virtualenv
deactivate
rm -rf env
SECOND:
check have pip
pip3 -V
if you don't have
sudo apt-get install python3-pip
FINALLY:
install virtualenv with nosite-packages
and make your virenviroment
sudo pip3 install virtualenv
virtualenv --no-site-packages -p /usr/bin/python3.6
. env/bin/activate
Check ~/.pip/pip.log
It could contain the error message
Could not fetch URL https://pypi.python.org/simple/pip/: 403 Client Error: [[[!!! BREAKING CHANGE !!!]]] Support for clients that do not support Server Name Indication is temporarily disabled and will be permanently deprecated soon. See https://status.python.org/incidents/hzmjhqsdjqgb and https://github.com/pypa/pypi-support/issues/978 [[[!!! END BREAKING CHANGE !!!]]]
If so, the fix is to upgrade to that last version of Python 2.7. See https://github.com/pypa/pypi-support/issues/978
In my case I could do that with add-apt-repository ppa:fkrull/deadsnakes-python2.7 && apt-get update && apt-get upgrade but YMMV may vary depending on distribution.
I had a similar problem, but in my case I was getting the error:
Downloading/unpacking bencode
Cannot fetch index base URL http://c.pypi.python.org/simple/
Could not find any downloads that satisfy the requirement bencode
No distributions at all found for bencode
Storing complete log in /home/andrew/.pip/pip.log
In my case I was able to fix the error by editing ~/.pip/pip.conf and changing http://c.pypi.python.org/simple/ to http://pypi.python.org/simple and then pip worked fine again.
I got this error message in ~/.pip/pip.log
Could not fetch URL https://pypi.python.org/simple/: connection error: [Errno 185090050] _ssl.c:344: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib
Will skip URL https://pypi.python.org/simple/ when looking for download links for regulargrid
I fixed it by updating my ~/.pip/pip.conf. It accidentally pointed to cacert.pem file that did not exist and looked like this
[global]
cert = /some/path/.pip/cacert.pem
I used to use the easy_install pip==1.2.1 workaround but I randomly found that if you're having this bug, you probably installed a 32bit version of python.
If you install a 64bit version of it by installing it from the source and then build you virtualenv upon it, you wont have that pip bug anymore.
I too used the chosen solution (downgrading pip) to work around this issue until I ran into another seemingly unrelated issue caused by the same underlying problem. Python's version of OpenSSL was out of date. Check your OpenSSL version:
python -c 'import ssl; print(ssl.OPENSSL_VERSION)'
If the version is 0.9.7, that should verify that OpenSSL needs to be updated. If you know how to do that directly, great (but please let me know in a comment). If not, you can follow the advice in this answer, and reinstall python from the 64 bit/32 bit installer instead of the 32 bit only installer from python.org (I'm using python 3.4.2). I now have OpenSSL version 0.9.8, and none of these issues.
Try doing reinstallation of pip :
curl -O https://pypi.python.org/packages/source/p/pip/pip-1.2.1.tar.gz
tar xvfz pip-1.2.1.tar.gz
cd pip-1.2.1
python setup.py install
If curl doesnot work , you will have proxy issues , Please fix that it should work fine. Check after opening google.com in your browser in linux.
The try installing
pip install virtualenv
In case you use a firewall, make sure outbound connections to port 443 are not blocked, e.g. run:
sudo iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT
I have met the same questions with you. When I realize it may be caused by unmatched version of numpy or pip, I uninstalled numpy and pip, then continue as this 'https://radimrehurek.com/gensim/install.html', at last I succeed!
C:\Users\Asus>pip install matplotlib
Downloading/unpacking matplotlib
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement matplotlib
Cleaning up...
No distributions at all found for matplotlib
Storing debug log for failure in C:\Users\Asus\pip\pip.log
I used 'easy_install pip==1.2.1' and it worked fine.
C:\Users\Asus>easy_install pip==1.2.1
Searching for pip==1.2.1
Reading https://pypi.python.org/simple/pip/
Best match: pip 1.2.1
Downloading ...
Then on using this command 'pip install matplotlib'
C:\Users\Asus>pip install matplotlib
Downloading/unpacking matplotlib
Downloading matplotlib-2.0.0b4.tar.gz (unknown size):
If you're running these commands in a Docker container on Windows, it may mean that your docker machine's network connection is stale and needs to be rebuilt. To fix it, run these commands:
docker-machine stop
docker-machine start
#FOR /f "tokens=*" %i IN ('docker-machine env') DO #%i
I'm now getting this in $HOME/.pip/pip.log:
Could not fetch URL https://pypi.python.org/simple/: HTTP Error 403: TLSv1.2+ is required
I don't have a straightforward solution for this, but I'm mentioning it as something to watch out for before you waste time on trying some of the other solutions here.
I'm obviously already using a https URL
There is no proxy or firewall issue
Using trusted-host didn't change anything (dunno where I picked this up)
For what it's worth my openssl is too old to even have ssl.OPENSSL_VERSION so maybe that's really the explanation here.
In the end, wiping my virtual environment and recreating it with virtualenv --setuptools env seems to have fixed at least the major blockers.
This is on a really old Debian box, Python 2.6.6.

Categories

Resources