How can I run pyqt5 on my Mac with M1chip (ppc64el architecture)? - python

Now. When I run it. The error comes
ImportError:
dlopen(/Users/v/Library/Python/3.8/lib/python/site-packages/PyQt5/QtWidgets.abi3.so,
2): no suitable image found. Did find:
/Users/v/Library/Python/3.8/lib/python/site-packages/PyQt5/QtWidgets.abi3.so:
mach-o, but wrong architecture
/Users/v/Library/Python/3.8/lib/python/site-packages/PyQt5/QtWidgets.abi3.so:
mach-o, but wrong architecture

After hours of trial and error, I was finally able to solve this. My successful configuration is:
Open terminal with Rosetta 2 (https://dev.to/courier/tips-and-tricks-to-setup-your-apple-m1-for-development-547g)
Use non-homebrew python (mine was in /usr/bin/python3) to create virtual environment
/usr/bin/python3 -m venv env
source env/bin/activate
Upgrade pip
pip install --upgrade pip
Install PyQt5
pip install PyQt5

I needed PyQt5 as a dependency for a Python library and this worked for me. See original post here.
brew install pyqt5
echo 'export PATH="/opt/homebrew/opt/qt#5/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/pyqt#5/5.15.4_1/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

What I ended up doing specifically for pyqt5 was:
brew install pyqt#5
I think for versions 4 and 6 this may work as well. When I went simply brew install pyqt that didn't work unfortunately.
note this is M1 Macbook only
One other thing to try as things settle down with M1s is to try pip3 install pyqt5 in a terminal launched in Rosetta mode (left click -> Get Info -> Open in Rosetta)
Edit (Nov 2022)
It seems that if you don't specifically need pyqt5, pyqt6 is now easily installable via pip on M1/M2 Macs.
python -m pip install pyqt6

I was hoping to install pyqt5 on my M1 mac without Rosetta. I was using it as a dependency of another project that I wanted to install in a venv which requires pyqt5 and was not installable via pipx (urh).
Unfortunately, there currently are no compatible wheels (curl --silent "https://pypi.org/pypi/PyQt5/json" | grep -i arm64), and attempting to install on 3.10 fails with AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'
Thankfully, the homebrew installation of pyqt5 is compiled for arm64 and works well.
My steps were:
$ # Install pyqt5 via homebrew
$ brew install pyqt#5
$ # Note that it's installed in python3.9, not 3.10
$ brew cat pyqt#5 | grep 'depends_on.*python'
depends_on "python#3.9"
$ # Make a python3.9 virtualenv with access to the system's site-packages
$ /opt/homebrew/bin/python3.9 -m venv --system-site-packages .venv
$ source .venv/bin/activate
At this point I was able to install urh into the virtualenv, using the arm64-compiled pyqt5 from hombrew, without neededing Rosetta (and without needing to further "pollute" my system site-packages), and it runs as expected (since the question was about running).

Try installing the pyqt under the ARM architecture as below
arch -arm64 brew install pyqt

In my case it's work: arch -x86_64 brew install pyqt
And all required pyqt start from arch -x86_64 or start from rosetta (through emulator).

You can use it from homebrew, this is the only way I found it working on Mac M1.
First:
brew install pyqt#5
Then:
brew --cellar
brew link --overwrite python
Then you must create/add an alias for python and put it in your .zprofile (Located in Users/username folder, if you press Shift+command+.
This must point to your homebrew python installation location.
alias python ='opt/homebrew/bin/python3'
That way it will link python with your homebrew python and you can run python test.py from terminal (Where your python files are located).
No matter how I tried with pip install, it just shown error and did not work.

I wanted to run PyQt5 under virtual environment with Python3.6.
The following procedures worked for me.
My settings are MBA M1 2020, macOS 11.3.1, and
pyenv versions
> system
> * 3.6.15
pip -V
> pip 21.3.1 from /Users/username/.pyenv/versions/3.6.15/lib/python3.6/site-packages/pip (python 3.6)
Then simply run:
pip install pyqt5-sip
pip install pyqt5
on the terminal (default one, not the one with Rosetta 2).

I had to install PyQt5==5.15.6on my MacM1 into an existing virtual environment.
It did not work using all the methods described here.
So, what I did is :
Open the terminal in rosetta mode
Navigate to my project and activate the virtual environment source venv/bin/activate
Install the package : pip install PyQt5==5.15.6
Open a regular terminal into my project and make sure everything was installed as per the requirements.txt : pip install -r requirements.txt
Everything is running smoothly, now.

If anyone is still having the same problem with installation of PyQT5, I would suggest you to rather lock your focus on PySide6. It is 99% similar to PyQT5 and works well with MacBook m1.
I've been digging the Internet for hours hoping to find the solution but it appears that PyQT5 and PyQT5-tools modules are somewhat broken on MacBook M1 when it comes to downloading them.

I was struggling with installing PyQt5 on M1 mac with MacOS 12.6 (Monterey) inside a virtual environment (using python 3.9). The final solution that worked for me was to use conda for creating and activating the virtual environment.
conda create --name venv python=3.9 conda activate venv
And then simply using conda to install PyQt5 as part of the pyqt package.
conda install pyqt

PyQt6 is out now and supports apple silicon:
https://stackoverflow.com/a/75224682/19486832
No conda support, but pip install is working fine:
python -m pip install PyQt6

Related

Installing Jupyter Notebook python package - version confusion

I usually work with pyCharm in which it is really easy to manage different python versions. (I use High Sierra, Mac)
In my settings I can see all of them and addon packages:
To be honest, I don't remember how I installed all of these, a bunch of them through brew though.
Now I am trying to run a Jupyter Notebook in python 3, it's using the python 3 kernel, but I am missing acp package.
So I pip install acp. ok.
The Notebook doesn't see the package. This makes me think it's not installing in the correct python version.
pip3 is not recognised as a command.
brew install python3 -> asks to update python 2 to version 3 (which I don't want).
I am quite confused now as how to intall the packages...
It may be installing with python executable your jupyter is not using.
you can directly install in jupyter shell by allowing python executable your jupyter is using:
import sys
!{sys.executable} -m pip install acp
To check your Python executables, you may open a terminal and type
touch ~/.bash_profile; open ~/.bash_profile
Then you will know which path your python exists in. Make sure to select the same path when you configure your project interpreter. Then you may like to upgrade your pip by typing in a terminal:
$ sudo pip install --upgrade pip
$ alias python=python3
$ python --version
Make sure python version is >3, after which that you may try:
pip3 install acp

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available

I am using Python 3.6. When I try to install "modules" using pip3, I face this issue:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available
For Windows 10
if you want use pip in normal cmd, not only in Anaconda prompt. you need add 3 environment paths.
like the followings:
D:\Anaconda3
D:\Anaconda3\Scripts
D:\Anaconda3\Library\bin
most people only add D:\Anaconda3\Scripts
MAC OS
I had the same problem on Mac OS(Mojave) and solved the problem as mentioned on this link - Openssl issue.
If you do not have Homebrew or don't know what is Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Or if you already have Homebrew installed:
brew update && brew upgrade
brew uninstall --ignore-dependencies openssl; brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb
Update:
Keep in mind, that I had to use --ignore-dependencies flag, because other packages installed that depend on OpenSSL.
Additional if the problem is caused after using pyenv, you can fix it by using:
brew reinstall python
For Debian users, the following may be of use:
sudo apt install libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev libtk8.6 libgdm-dev libdb4o-cil-dev libpcap-dev
Then cd to the folder with the Python 3.X library source code and run:
./configure
make
make install
I'm using Windows 10 and installed Miniconda 3 with Python 3.7.
I solved this error by following this https://github.com/conda/conda/issues/8273
Specifically, I copied the following files from C:\Users\MyUser\Miniconda3\Library\bin to C:\Users\MyUser\Miniconda3\DLLs:
libcrypto-1_1-x64.dll
libcrypto-1_1-x64.pdb
libssl-1_1-x64.dll
libssl-1_1-x64.pdb
For centos 7:
Install openssl:
sudo yum install openssl-devel
now goto python directory were we extracted the python tar,
run below commands
sudo ./configure
sudo make
sudo make install
This will fix the problem in centos...
For future Oracle Linux users trying to solve this, below is what worked for me.
First install missing libs:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel
readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
Then cd to your Python3.X library and run:
make
make install
macOS, pyenv
In case of your python being an pyenv installed one, where pyenv is installed with homebrew on macOS, there might me a newer version available which fixes this:
$ brew update && brew upgrade pyenv
Then reinstalling the python version:
$ pyenv install 3.7.2
pyenv: /Users/luckydonald/.pyenv/versions/3.7.2 already exists
continue with installation? (y/N)
Note, it is a bit dirty to overwrite the existing python install like that, but in my case it did work out. Probably cleaner to delete it and then recreate it properly.
For Windows 10,windows 7
If pip install is not working on CMD prompt, run it using Anaconda prompt - it works.
https://github.com/pypa/virtualenv/issues/1139
Worked for me.
sudo apt-get install libssl-dev
Use this to enable ssl for pip.
Let me know if someone encounters issues.
Encountered this issue while installing python 3.8 from source on ubuntu. The steps needed to install it successfully alongside the default python 3.7 are summarised below :
sudo apt -y install libssl-dev zlib1g-dev build-essential
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
tar -xf Python-3.8.0.tgz
cd Python-3.8.0/
./configure --enable-optimizations
make
sudo make altinstall
The install instruction for zlib1g-dev and build-essential is redundant, as ubuntu desktop already has these, but was necessary for some of Amazon's EC2 instances. python 3.8.0 is the current release just now, but should be replaced with the latest available.
These instructions are best for keeping python 3.7 as the default for python3, and running python 3.8 in a virtual environment.
Similar to the above solution reinstall the python version with pyenv.
Somehow, I upgraded my openssl which broke the pyenv version python.
pyenv install 3.6.8
python-build: use openssl#1.1 from homebrew
python-build: use readline from homebrew
...
The first line says it relies on the homebrew openssl.
In my case, I reinstalled Python. It solved the problem.
brew reinstall python
For OpenSUSE in the same manner, but a few changes of listed above packages:
zypper install zlib-devel libopenssl-devel ncurses-devel sqlite3-devel readline-devel tk-devel gdbm-devel libpcap-devel xz-devel
Then cd to Python sources dir and
make
make install
or
make
make altinstall
And perhaps
ln -s /usr/local/lib64/python3.6/lib-dynload/ /usr/local/lib/python3.6/lib-dynload
should be executed for OpenSUSE users. See Python 3.7 install not working on openSUSE Leap 42.3
Just try installing through Anaconda prompt
I ran into this issue with Visual Studio Code installing pylint from the VS Code prompt.
I was able to overcome the issue by opening the Anaconda installation directory and running
pip install pylint
Then VS Code was happy, but that did not fix the issue as running
& C:/Users/happy/Anaconda3/python.exe -m pip install -U pylint
pretty much gave the same error so it seems that VS Code is unable to access the python modules.
Note that VS Code picks up the first python env it see when installed, the bottom left of the screen indicates which env is being used. Clicking on that area allows to set the environment. So even if you ran the pip install for an environment VS Code could be looking at a different one.
Best approach was to make sure that VS code had the correct python environment selected and that same environment is in the system PATH (under System Properties --> Advanced --> Environmental Variables)
Under the Path Variable, Edit and browse to the specific Anaconda directory that you want VSCode to use and add to PATH, I needed to Add the following:
C:\Users\happy\Anaconda3\
C:\Users\happy\Anaconda3\Scripts\
C:\Users\happy\Anaconda3\Library\bin\
C:\Users\happy\Anaconda3\Library\mingw-w64\bin\
Your Anaconda installation directory may differ.
One note is that Windows does not have the PATH variable take effect until you restart the terminal. In this case close and re-op VS code. If using a Terminal or PS Shell then close and reopen and check Path to make sure it is included.
The problem probably comes from your installed openssl package version. That was the case for me and I fixed this issue just upgrading it. I'm on Mac OS, using brew :
brew upgrade openssl
If you installed python with brew, this should directly fix the issue with it, as python is dependent on openssl
Newest Python 3.8.4 or higher should able to support https protocol out of box. If you still have old python installation on your pc - either download & install python3 manually, or using Chocolatey:
If you don't have Chocolatey, install it - from here: https://chocolatey.org/docs/installation
You can just copy paste one command line liner and execute it from command prompt with elevated priviledges.
choco install python3
if you don't have python3 installed, or you you have it installed - then:
choco upgrade python3
Notice also that you can use also anaconda distribution, as it has built-in python with https support, but this rather ancient instructions, no need to follow them anymore.
Install anaconda, using command line:
choco install anaconda3
Set environment variables:
set PATH=C:\tools\Anaconda3\Scripts;C:\tools\Anaconda3;C:\tools\Anaconda3\Library\bin;%PATH%
and then run command which failed. In my case it was:
pip install conan
Anaconda uses separate python installation, and pip is also anaconda specific.
As Tokci said, it also works for Windows 7.
"Go with the mouse to the Windows Icon (lower left) and start typing "Anaconda". There should show up some matching entries. Select "Anaconda Prompt". A new command window, named "Anaconda Prompt" will open."
Then pip works.
The following also helped to import xgboost:
https://www.youtube.com/watch?v=05djBSOs1FA
If someone is using Arch Linux OS, I solved the TLS/SSL problem by running this:
sudo pacman -S openssl
Then I could use pip to install the package I needed:
pip install openpyxl
Go to Anaconda prompt and type (if you have python 3.x installed on your engine) :
py -m pip install pymysql
i was having the same issue and this solved my problem. later after doing this you can import pymysql in power shell or any other prompt.
The issue is due to OpenSSL package is missing on your PC.
If pip install openpyxl also gives error.
you can fix this by installing OpenSSL(Win64 OpenSSL v1.1.1g) from below site :
slproweb.com/products/Win32OpenSSL.html
Restart the IDE you are using, for changes to be in effect.
In Windows 10 SQL Server 19 the solution is known.
Copy the following files:
libssl-1_1-x64.dll
libcrypto-1_1-x64.dll
from the folder
C:\Program Files\Microsoft SQL Server\MSSSQL15.MSSQLSERVER\PYTHON_SERVICES\Library\bin
to the folder
C:\Program Files\Microsoft SQL Server\MSSSQL15.MSSQLSERVER\PYTHON_SERVICES\DLLs
Then open a new DOS command shell prompt.
From https://learn.microsoft.com/en-us/sql/machine-learning/troubleshooting/known-issues-for-sql-server-machine-learning-services?view=sql-server-ver15#7-unable-to-install-python-packages-using-pip-after-installing-sql-server-2019-on-windows
Worked for me.
pkg install openssl
Use this to enable ssl.
Currently there is same issue in Anaconda prompt (Anaconda3) on Windows 10. Here is workaround: https://github.com/ContinuumIO/anaconda-issues/issues/10576
Fixed this without having to change anything related to TSL/SSL.
I was trying to see if the same thing was happening to pip, and saw that pip was broken. Did some digging and realized it's probably caused by Homebrew deleted python#2 on February 1st, 2020.
Running brew uninstall python#2 to delete python2 installed by Homebrew.
Destroyed the virtual env created using python3 and created a new one. pip3 installing works fine again.
I am on macOS and I had used brew but what Vaulstein mentioned in his answer didn't cover my case.
I run the following commands to make sure my current python was not installed by brew
brew list | grep python
python
python#2
brew info python
python#3.8: stable 3.8.3 (bottled)
Interpreted, interactive, object-oriented programming language
https://www.python.org/
Not installed
...
So I download the latest 3.8.5 from https://www.python.org/ and when installing it I saw following information
Certificate verification and OpenSSL
This package includes its own private copy of OpenSSL 1.1.1. The
trust certificates in system and user keychains managed by the
Keychain Access application and the security command line utility are not used as defaults by the Python ssl module
After installed 3.8.5 it fixed the problem.
I got into this problem using Ubuntu, pyenv and Python 3.8.1 managed by pyenv. There was actually no way to get pip to work correctly, since every time I tried to install anything, including pip itself, the same error showed up.
Final solution was to install, via pyenv, a newer version, in this case 3.8.6. Apparently, from 3.8.4 Python is prepared to run SSL/TLS out of the box, so everything worked fine.
I simply solved the problem with following command:
brew upgrade python#3.9
SSL is included by default on this version!
In my case I was running into issues with my $PATH on Linux. This can also happen on MacOS.
Check to see if /usr/bin/pip3 install package_name_goes_here works for you. If so then run
which pip3 this will tell you which is the first directory that pip3 is installed in.
If it is something like /usr/local/bin/pip3 which is different from /usr/bin/pip3 then you may need to adjust your $PATH.
Run
echo $PATH and copy the result.
The PATH is simply a colon separated list of directories that contain directories. Bash will always return the first instance of the program that you are attempting to execute. Move all the system directories upfront. Here is a list of some of the system directories:
/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
If that fails then verify you have openssl installed by running openssl version -a if not then install openssl.
If you've installed anaconda via scoop, and encounter this error while using pip from within a conda environment you can resolve it by...
Adding these to your path
C:\Users\YOUR_USERNAME\scoop\apps\anaconda3\current
C:\Users\YOUR_USERNAME\scoop\apps\anaconda3\current\Scripts
C:\Users\YOUR_USERNAME\scoop\apps\anaconda3\current\Library
C:\Users\YOUR_USERNAME\scoop\apps\anaconda3\current\Library\bin
Installing openssl via scoop
scoop install openssl
And copying the following DLLs from ..\anaconda3\Library\bin to ..\anaconda3\DLLs
References:
https://stackoverflow.com/a/54897379
https://stackoverflow.com/a/60405693

Install python modules in mac osx

I am new to python. I am using python 3.5 on mac os x el capitan.
I tried using the command 'pip install requests' in the python interpreter IDLE. But it throws invalid 'syntax error'.
I read about installing modules is only possible in the command line.
So I moved to TERMINAL, but no command is working here also.
(I tried 'python -m pip install requests')
I read that mac os x comes with python 2.7 already installed and I ran 'easy_install pip' but it also works on the 2.7 version.
Then there's discussion about the PATH settings also.
Can please anybody explain to me how I can use my current version in TERMINAL window and what is the PATH scenario.
I am familiar with the environment variable settings and adding pythonpath in windows but not on mac.
Here is what you should do.
Use homebrew to install python 2.7 and 3.5 in a virtual environment.
pip install virtualenv
Then make a directory called virtualenvs in your root folder and add local files with.
cd virtualenvs
virtualenv venv
activate a virtualenv with source ~/virtualenvs/bin/activate
Then use pip to install brew in this virtualenv pip install brew
Then install python 2.7 as python and python 3 as python3:
brew update
brew install python
brew install python3
Then you can use python and python3 and not have to worry about the local install.
Then to run a file python3 filename.py
Followed this guide.
https://docs.python.org/3/using/mac.html
Found python3.5 in usr/local/bin instead of the default usr/bin where the default 2.7 exists.
The 3.5 Package automatically genrates an alias for itself that is python3.5 for use in terminal.
Ran the command 'python3.5 -m pip install requests' and everything went good.

How to install packages in different version of python?

I have a MacBook Pro that came pre-installed with python2.7. I later installed python3 and ipython notebook. I installed pip too to install packages, and am able to install packages and run program from python3. However, for another project I need to run code in python2.7, and I am not sure how to install it in python2.7 folder.
I tried using pip for installing packages to 2.7, but it kept giving error saying package already exists. When I check for version of python using --version, I see 2 pythons installed. However, when I check for pip and pip3, both seem to be in th same folder.
Any tips on how to install packages in python2.7, without making any changes to 3.3? I am using python3 and ipython notebooks for another project.
viveks-mbp:~ vivekyadav$ which pip
/Library/Frameworks/Python.framework/Versions/3.3/bin/pip
viveks-mbp:~ vivekyadav$ which pip3
/Library/Frameworks/Python.framework/Versions/3.3/bin/pip3
viveks-mbp:~ vivekyadav$ which python
/usr/bin/python
viveks-mbp:~ vivekyadav$ which python3
/Library/Frameworks/Python.framework/Versions/3.3/bin/python3
You can use the virtualenv to create a kind of sandbox.
$ virtualenv <work-directory>
$ source <work-directory>/bin/activate
The last command initiate your virtual environment, totally isolated from the system. So every pip command will install the package inside this directory.
But you have to run your application inside the virtual environment too.

Why 'python3 -m venv myenv' installs older version of pip into myenv than any version of pip I can find anywhere on the system?

This is not causing me any problem that I can't solve by activating the virtual environment and running pip install -U pip, but I always wonder where the older version of pip is coming from.
I'm using OS X 10.7.5. When I create a virtual environment using either pyvenv-3.4 myenv or python3 -m venv myenv, the version of pip that is installed inside the virtual environment is 6.0.8, but I have upgraded my global pip to 6.1.1.
Here is a terminal session demonstrating what I mean:
$ python3 -m venv myenv
$ myenv/bin/pip -V
pip 6.0.8 from /Users/dust/Desktop/myenv/lib/python3.4/site-packages (python 3.4)
Here is what I would like to occur:
$ source myenv/bin/activate
(myenv)$ pip -V
UPDATED SYSTEM VERSION HERE WOULD BE NICE
I can't find a pip 6.0.8 anywhere else, other than what is created inside virtual environments.
Here are the outputs of various commands that I have use to try and figure this out:
$ which pip
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip
$ which pip3
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip3
$ pip -V
pip 6.1.1 from /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (python 3.4)
$ pip3 -V
pip 6.1.1 from /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (python 3.4)
I even tried using find:
$ find / -type f -name pip 2>&1 | awk '! /^f.*$/'
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip
/usr/local/bin/pip
$ find / -type f -name pip3 2>&1 | awk '! /^f.*$/'
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip3
I thought maybe that the /usr/local/bin/pip might have been the culprit, but no:
$ /usr/local/bin/pip -V
pip 6.1.1 from /Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg (python 2.7)
Hmm. Perhaps the OS X python has it?
$ /usr/bin/python
>>> import pip
>>> pip.__version__
'6.1.1'
6.1.1 is reported no matter which distribution of python I ask, whether it be OS X's 2.7.1, python.org's 2.7.9, or python.org's 3.4.3.
Is it possible (or advisable) to update the version of pip that gets put into a virtual environment?
I face the same issue, running OSX 10.10.2 and python 3.4.2. Most recently I created a virtual environment in a debian wheezy machine with python 3.4.3 and also ended up with an older version of pip than available. had to upgrade pip.
I've been upgrading pip within the virtual environment to 6.1.1 from 6.0.8 manually, because I'm o.c.d about software library versions that way - and yes, I am upgrading my python 3 version to 3.4.3 right now. Anyway, my system's python3-pip is the latest version 6.1.1, so I've also wondered why pyvenv creates a new virtual environment and loads it with old pip.
I haven't noticed anything bad happen in any of the virtual environments due to upgrading pip, (but on the flip side, I haven't noticed anything good either) Apparently the new pip is faster -- didn't notice, and outputs less junk on successful installs because user's don't care -- also didn't notice, probably because i'm one of those that don't care, and also comes with a state-of-the art coffee machine capable of latte art to boot!!! -- still waiting on sudo pip install latte to finish :(
So, to answer your question, it is definitely possible, and probably advisable to upgrade, because apparently the new pip fixes some bugs and goes faster, but I guess the speed up isn't that major, and the bug fixes don't affect all that many people (I've never faced a bug with my usage of the old pip).
You can link to system site-packages using the flag --system-site-packages when you create a new virtual environment, like this
pyvenv myenv --system-site-packages
This will link to your system wide version of pip, and would remove the annoyance that is manually upgrading pip on every virtual environment, but if you do this, then is your virtual environment all that virtual?
update: following my rant above, I went into the venv package's source to dig. pip is set up by a method called _setup_pip in the file __init__.py, line 248
def _setup_pip(self, context):
"""Installs or upgrades pip in a virtual environment"""
# We run ensurepip in isolated mode to avoid side effects from
# environment vars, the current directory and anything else
# intended for the global Python environment
cmd = [context.env_exe, '-Im', 'ensurepip', '--upgrade',
'--default-pip']
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
So, venv seems to be calling ensurepip from the shell using the subprocess module.
One more minute of google-fu gave me this from the documentation for ensurepip.
ensurepip.version()
Returns a string specifying the bundled version of pip that will be installed when bootstrapping an environment.
So, from the command line, the following code:
$ python3 -c 'import ensurepip; print(ensurepip.version())'
6.0.8
displays my current pip that will be bootstrapped with ensurepip.
I guess we're stuck with the old version of pip for every new install until ensurepip gets upgraded, as I can't find a way to upgrade the version of pip that comes with ensurepip
Newer
If you want to "hotpatch" your installed python, just modify the versions listed in ensurepip/__init__.py and replace the two files in ensurepip/_bundled. You can find this location by running find * | grep ensurepip from the directory where python is installed. On macOS with Homebrew, this is the location: /usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ensurepip
You will also want to delete the ensurepip/__pycache__ directory that contains the .pyc files.
My older, build-time fix:
You are able to update the bundled versions of pip and setuptools by patching Python before building it from source. The following patch will update the bundled versions of pip and setuptools to the current available today. You will want to invoke configure with the following option: --with-ensurepip=upgrade
Those whl files are downloaded from PYPI here:
https://pypi.org/project/pip/#files
https://pypi.org/project/setuptools/#files
diff -ru Python-3.7.1/Lib/ensurepip/__init__.py Python-3.7.1.new/Lib/ensurepip/__init__.py
--- Python-3.7.1/Lib/ensurepip/__init__.py 2018-10-20 06:04:19.000000000 +0000
+++ Python-3.7.1.new/Lib/ensurepip/__init__.py 2018-11-27 02:36:19.301655008 +0000
## -8,9 +8,9 ##
__all__ = ["version", "bootstrap"]
-_SETUPTOOLS_VERSION = "39.0.1"
+_SETUPTOOLS_VERSION = "40.6.2"
-_PIP_VERSION = "10.0.1"
+_PIP_VERSION = "18.1"
_PROJECTS = [
("setuptools", _SETUPTOOLS_VERSION),
Only in Python-3.7.1/Lib/ensurepip/_bundled: pip-10.0.1-py2.py3-none-any.whl
Only in Python-3.7.1.new/Lib/ensurepip/_bundled: pip-18.1-py2.py3-none-any.whl
Only in Python-3.7.1/Lib/ensurepip/_bundled: setuptools-39.0.1-py2.py3-none-any.whl
Only in Python-3.7.1.new/Lib/ensurepip/_bundled: setuptools-40.6.2-py2.py3-none-any.whl
If you're lucky, you can bump it up with a Python patch.
Is your Python outdated? This is using macports, but any of brew, apt should do.
port outdated
python36 3.6.9 < 3.6.10
Let's fix that:
sudo port upgrade python36
And now... drumroll, in my newly-recreated venv, it seems that the Python patch has brought along the latest pip.
pip --version shows 20.0.2, it was at 18 previously and that's precisely what it was complaining about in the venv.
This is after spending a ludicrously long amount of time trying to figure out how to update my user-level Python 3.6 version of pip, on a mac where, of course, if you quit the virtualenv you are at Python 2.7 and where Python 3.6, installed through macports, doesn't seem to have a pip command to work with, until you build a venv.
From looking at /opt/local/Library/Frameworks/Python.framework/Versions/3.6, where macports puts things, I suspect Utknonos is on to something, so +1.
There really should be something a bit more obvious, like a pip-system-selfupdate command or a pip36 that comes along with python36. Especially considering that a search of pip upgrade will return tons of hits on anything but this subject.
Note: after my update, even though Python has been updated
(venv)$ pwd
/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6
(venv)$ grep PIP_VERSION ensurepip/__init__.py
_PIP_VERSION = "18.1"
(venv) $python --version
Python 3.6.10
(venv) $pip --version
pip 20.0.2 from .../venv/lib/python3.6/site-packages/pip (python 3.6)

Categories