Trying to migrate from virtualenv to venv (python3). Also would like to use pyenv to manage multiple versions of python 3.x on my Mac.
Following this article, I installed pyenv, pyenv-virtualenv and pyenv-virtualenvwrapper via brew without a problem:
brew install pyenv
brew install pyenv-virtualenv
brew install pyenv-virtualenvwrapper
Modified my .zsh_env.sh in ~/.config/zsh_env.sh like so:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/workspace
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Installed two Python versions:
➜ ~ pyenv versions
system
2.7.15
* 3.7.2 (set by /Users/ugur/.python-version)
Trying to create a virtual environment, but I get a complaint that pip is missing:
➜ ~ pyenv virtualenv 3.7.2 jupyter3
pyenv: pip: command not found
The `pip' command exists in these Python versions:
2.7.15
If I try to run pip in my terminal, I get the same error:
➜ ~ pip
pyenv: pip: command not found
The `pip' command exists in these Python versions:
2.7.15
pip3 seems to be installed/seen though:
➜ ~ pip3
Usage:
pip3 <command> [options]
Commands:
install Install packages.
download Download packages.
... (omitted)
How can I use pyenv in combination with venv to manage environments and python versions?
Edit
Tried to install pip via pip3 like so (without success):
➜ ~ pip3 install pip
Requirement already satisfied: pip in ./.pyenv/versions/3.7.2/lib/python3.7/site-packages (18.1)
You are using pip version 18.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
➜ ~ pip install --upgrade pip
pyenv: pip: command not found
The `pip' command exists in these Python versions:
2.7.15
Edit 2
Not even aliasing pip helped:
➜ ~ alias pip=pip3
➜ ~ pyenv virtualenv 3.7.2 jupyter3
pyenv: pip: command not found
The `pip' command exists in these Python versions:
2.7.15
You can just create a similink as such
ln -s /usr/bin/pip3 /usr/bin/pip
Now calling pip will actually be pip3.
Note : This doenst work if python was installed with brew, as the directory isnt /usr/bin, as pointed out in below comment.
Related
Creation of venv with python3 is ok.
However, when I run pip install requests in the venv, the package has been installed in the normal python site-package outside of the venv.framework folder. The pip doesn't install package in the venv.
I've installed python3 from brew.
I've installed python3.9 and python3.10, which are downloaded from the python homepage.
Outside of the venv, the 'which' command looks like this.
which python
/usr/local/bin/python
which python3
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
which python3.9
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9
which python3.10
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10
which pip
pip: aliased to /usr/local/bin/pip3
which pip3
/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3
which pip3.9
/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3.9
which pip3.10
/Library/Frameworks/Python.framework/Versions/3.10/bin/pip3.10
echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Inside of the venv:
which python
/....../venv_test/venv/bin/python.
which python3
/....../venv_test/venv/bin/python3
which python3.9
/....../venv_test/venv/bin/python3.9
which python3.10
/....../venv_test/venv/bin/python
which pip
pip: aliased to /usr/local/bin/pip3
which pip3
/....../venv_test/venv/bin/pip3
which pip3.9
/....../venv_test/venv/bin/pip3.9
which pip3.10
/....../venv_test/venv/bin/pip3.10
echo $PATH
/....../venv_test/venv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Please help.
Upgrading pip does not do anything, just tells me to upgrade Pip again and that the requirements are satisfied--however, I am on an old pip version. This is Python27, I get the same issue whether I am in a virtual environment or not.
Output:
C:\Python27>python -m pip install --upgrade pip
Requirement already up-to-date: pip in c:\python27\lib\site-packages
You are using pip version 9.0.1, however version 19.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Versions Installed:
$ pip --version
pip 9.0.1 from c:\python27\lib\site-packages (python 2.7)
$ pip --version
pip 9.0.1 from c:\users\aroytikh\dev\flask-tutorial\venv\lib\site-
packages (python 2.7)
(venv)
I think it how to update pip will help you and make sure that you are running command prompt as Administrator. you can do this by right click on the "Command Prompt" application and choose "Run as administrator" and type this command in your command prompt.
python -m pip install -U pip
try this if it isn't working for you..
Download Pip 19.1.1
Install Pip using this command
$ python -m pip install downloads/pip-19.1.1-py2.py3-none-any.whl
or if it is tar.gz file then
$ python -m pip install downloads/pip-19.1.1.tar.gz
When I try to install anything with (for example) python3 -m pip install numpy , I get
Could not find a version that satisfies the requirement numpy (from versions: )
No matching distribution found for numpy
I've tried upgrading pip3 with python3 -m pip install --upgrade pip but have only gotten
Requirement already up-to-date: pip in
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-
packages
and when I do python3 -m pip --version I get
pip 7.1.2 from /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (python 3.5)
I'm unable to install any modules at all. Any advice? I am on MacOS.
To solve your problem, I suggest you use brew as the package manager and install python, not as binary from the python.org but binary using brew (https://brew.sh), I hope it'll fix your troubles, during the installation process.
Install brew package manager:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install "python3" on your machine (python2 can be installed in the same way):
$ brew install python3
Check what version of python you are using:
$ which python3
Output(should look like): /usr/local/bin/python3
Check what pip you are using:
$ which pip3
Output(should look like): /usr/local/bin/pip3
Then you can install any package using "pip":
$ pip3 install virtualenv
Verify that package was installed:
$ pip3 freeze | grep virtualenv
Update pip manually, first download pip:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
and then run the command
python3 get-pip.py
Now you can install with pip3
pip3 install numpy
How do I get my virtual environments to use my system upgraded pip?
Before creating a virtualenv, pip shows version 9.0.1, but inside the virtual environment it reverts back to 8.1.1, forcing me to upgrade all my virtualenv pips.
$ pip --version
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ pip --version
pip 8.1.1 from /tmp/venv/lib/python3.5/site-packages (python 3.5)
(venv) $ pip install --upgrade pip
(venv) $ pip --version
pip 9.0.1 from /tmp/venv/lib/python3.5/site-packages (python 3.5)
When you create your virtualenv with the command
python3 -m venv venv
Your current Python 3 installation is used as the basis of your virtualenv.
Run the command
pip3 install --upgrade pip
outside of your virtualenv to upgrade the version of pip you have installed then create a new virtualenv.
I have my deployment system running CentOS 6.
It has by default python 2.6.6 installed. So, "which python" gives me /usr/bin/python (which is 2.6.6)
I later installed python3.5, which is invoked as python3 ("which python3" gives me /usr/local/bin/python3)
Using pip, I need to install a few packages that are specific to python3. So I did pip install using:-
"sudo yum install python-pip"
So "which pip" is /usr/bin/pip.
Now whenever I do any "pip install", it just installs it for 2.6.6. :-(
It is clear that pip installation got tied to python 2.6.6 and invoking pip later, only installs packages for 2.6.6.
How can I get around this issue?
If pip isn’t already installed, then first try to bootstrap it from the standard library:
$ python3.5 -m ensurepip --default-pip
If that still doesn’t allow you to run pip:
Securely Download get-pip.py.
Run sudo python3.5 get-pip.py.
Now you can use pip3 to install packages for python3.5. For example, try:
$ sudo pip3 install ipython # isntall IPython for python3.5
Alternatively, as long as the corresponding pip has been installed, you can use pip for a specific Python version like this:
$ python3.5 -m pip install SomePackage # specifically Python 3.5
References:
Ensure you can run pip from the command line
work with multiple versions of Python installed in parallel?
I have python 3.6 and 3.8 on my Ubuntu 18.04 WSL machine. Running
sudo apt-get install python3-pip
pip3 install my_package_name
kept installing packages into Python 3.6 dist directories. The only way that I could install packages for Python 3.8 was:
python3.8 -m pip install my_package_name
That installed appropriate package into the Python 3.8 dist package directory so that when I ran my code with python3.8, the required package was available.
Example of how to install pip for a specific python version
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
/opt/local/bin/python2.7 get-pip.py
Script is from official doc: https://pip.pypa.io/en/stable/installing/
On Ubuntu 18.04.1 LTS I wanted to install pip for my second python version (python3) and the following command did the trick for me:
$ sudo apt install python3-pip