I'm trying to set up a virtual environment. I have a Mac, using Mac OS Big Sur 11.1. I have installed the latest stable version of python, but when I enter this command into the terminal window
-m pip install pipenv pip --upgrade
I get the following error
zsh: command not found: -m
before, it would say
"No module named pip"
Do I have to install pip separately with
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
I thought pip was included by default when you install python? I think I might have pip because when I type
python3 -m pip
into the command line, I get a long list of commands (install packages, download packages, etc.) General options... Thus should I install pip? one person on reddit said,
Pip is not necessarily included with any version of Python. In many
distributions, it must be installed separately.
If python3 -m pip works, then you have a bad install, not a missing
one.
thus did I incorrectly install python? When I was installing it there was no option to
"add python to PATH"
Do I have to do this on a mac? If I input
python3 -V
in terminal, I get
Python 3.9.2
Thanks
i solved this by running,
pip3 install pip --upgrade
Related
I am trying to use these steps with bitbucket CI to deploy an application:
script:
- apt-get update
- apt-get install -y python-dev
- curl -O https://bootstrap.pypa.io/get-pip.py
- python get-pip.py
... and a few more steps
However, the python get-pip.py step fails with this error:
Traceback (most recent call last):
File "get-pip.py", line 24226, in <module>
main()
File "get-pip.py", line 199, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
from pip._internal.cli.main import main as pip_entry_point
File "/tmp/tmpUgc5ng/pip.zip/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
Why isn't it working now? Does it depend on the operating system?
For the equivalent issue with upgrading pip in old Python installations, see Upgrading pip fails with syntax error caused by sys.stderr.write(f"ERROR: {exc}").
pip 21.0 dropped support for Python 2 and 3.5. The later versions require Python 3.6+. The syntax f"" is supported by Python 3.6+.
To install pip for Python 2.7 install it from https://bootstrap.pypa.io/pip/2.7/ :
- curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py
- python get-pip.py
- python -m pip install --upgrade "pip < 21.0"
The last command is to upgrade to the latest supported version.
For Python 2.7 the latest supported is currently pip 20.3.4.
For Python 3.6 install from https://bootstrap.pypa.io/pip/3.6/
For Python 3.5 install from https://bootstrap.pypa.io/pip/3.5/
For Python 3.4 install from https://bootstrap.pypa.io/pip/3.4/
For Python 3.4 the upgrade command is
python -m pip install --upgrade "pip < 19.2"
I solved it by firstly run
python -m pip install --upgrade "pip < 19.2"
and then
python -m pip install --upgrade "pip < 21.0".
It seems reinstall my pip 20.3.4 and the error disappreared!
This worked for me:On Mac:
Install pyenv as well as upgrade your python following the instructions on this here
Then in your terminal, if you run python -V and you still get the old version(system predefined version) showing:
To resolve this:
In your terminal run: alias python=python3
Then in your terminal execute python and you should now see that your system is using the python version you installed-:That is if you followed and completed the steps Here Correctly.
Restart your terminal(close/reopen):
Now you can finally install pip:
Read more about pip instalation steps [here][3]
1:In your terminal execute :$ python -m ensurepip --upgrade
2: Download the script, from https://bootstrap.pypa.io/get-pip.py.
But..**NB**: instead of navigating to the exact link provided,check out the available versions of pip here: pipversions
Select the latest version:
Then select getpip.py link to get the file and save it into your directory on your machine:
cd into the folder where you saved the newly downloaded script and execute:
Then execute:
python get-pip.py
Pip installed successfully:
For me python 3.5 on aws ec2 below worked
curl -O https://bootstrap.pypa.io/pip/3.5/get-pip.py
Then
sudo python3.5 get-pip.pyenter image description here
I have also tried all thing but my solution was download old get-pip version and install.
download: curl -O https://bootstrap.pypa.io/2.7/get-pip.py the file get-pip.py
install: python get-pip.py or python2 get-pip.py
enjoy
This is worked on Debian systems.
Edit: A better solution is always to install a Python version that is long supported. If at all you need to work with an older version - only then must one resort to the above workaround.
Uninstall existing pip on your machine
Run this cmd in ubuntu or any linux machine
curl https://bootstrap.pypa.io/pip/3.5/get-pip.py -o get-pip.py
python3 get-pip.py
It will work
I'm trying to prevent this warning every time I create a fresh .venv:
> /Users/pi/.pyenv/versions/3.10.0/bin/python -m venv .venv
> . .venv/bin/activate
> pip install ipykernel # or anything
WARNING: You are using pip version 21.2.3; however, version 22.2.2 is available.
You should consider upgrading via the '/Users/pi/code/foo/.venv/bin/python -m pip install --upgrade pip' command.
Somehow pyenv has populated my fresh .venv with an out-of-date pip.
If I execute the suggested command it will upgrade my .venv's pip. But I don't want to be doing that every time I create a .venv.
I figured this might fix it, but it doesn't:
> /Users/pi/.pyenv/versions/3.10.0/bin/python -m pip install --upgrade pip
Requirement already satisfied: pip in /Users/pi/.pyenv/versions/3.10.0/lib/python3.10/site-packages (22.2.1)
Collecting pip
Using cached pip-22.2.2-py3-none-any.whl (2.0 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 22.2.1
Uninstalling pip-22.2.1:
Successfully uninstalled pip-22.2.1
Successfully installed pip-22.2.2
What is actually happening when I execute the above command? I was expecting it to update the pip for the python version created/maintained by pyenv. Which it seems to be doing:
🧢 pi#pPro18-4 ~/.pyenv/versions/3.10.0
> find . -name 'pip*'
./bin/pip3
./bin/pip
./bin/pip3.10
./lib/python3.10/site-packages/pip
./lib/python3.10/site-packages/pip-22.2.2.dist-info
🧢 pi#pPro18-4 ~/.pyenv/versions/3.10.0
> ./bin/pip --version
pip 22.2.2 from /Users/pi/.pyenv/versions/3.10.0/lib/python3.10/site-packages/pip (python 3.10)
So why isn't this pip getting copied into my .venv when I create it?
I thought that was the way .venv creation worked.
How to clean up my pyenv Python installation so that it spawns up-to-date .venvs?
EDIT:
Insight from #python on IRC/Libera:
grym: I don't think you can; i just get in the habit of python -m venv somevenv && somevenv/bin/python -m pip install --upgrade pip setuptools wheel
jinsun: python -m venv --upgrade-deps .venv is a simple solution if you were just annoying by the pip warning (...) it is updating the pip inside the venv, forget about the base python, I don't even have pip in the base python
This is the use case for pyenv-hooks
pyenv-hooks are scripts that are executed by pyenv whenever certain commands are run. You can create hooks for regular commands like: exec, rehash, which, but it can also be a plugin command, like virtualenv. The scripts can be written in any language.
Here is the wiki with official instructions.
You can have a hook by creating a script at the following location:
$PYENV_ROOT/pyenv.d/<hook-name>/<your-script-name>
For example, to create a hook that upgrades pip, create a new script within this path:
$PYENV_ROOT/pyenv.d/virtualenv/after.bash
With contents:
after_virtualenv 'PYENV_VERSION="$VIRTUALENV_NAME" pyenv-exec pip install --upgrade pip'
after_virtualenv is the command that tells pyenv when to execute. First, it sets the pyenv version to the name of the virtualenv we just created. with the variable $VIRTUALENV_NAME. Then it upgrades pip itself.
More details in this article.
I originally posted it as a comment, but was suggested to make it a proper answer.
An easier approach is to use the upgrade-deps flag when you create a virtual environment. Like this:
python3 -m venv --upgrade-deps .venv
It was added on python3.9, and according to the official docs:
--upgrade-deps
Upgrade core dependencies (pip, setuptools) to the latest version in PyPI
So, in other words, it will install pip and upgrade right away.
I am trying to use these steps with bitbucket CI to deploy an application:
script:
- apt-get update
- apt-get install -y python-dev
- curl -O https://bootstrap.pypa.io/get-pip.py
- python get-pip.py
... and a few more steps
However, the python get-pip.py step fails with this error:
Traceback (most recent call last):
File "get-pip.py", line 24226, in <module>
main()
File "get-pip.py", line 199, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
from pip._internal.cli.main import main as pip_entry_point
File "/tmp/tmpUgc5ng/pip.zip/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
Why isn't it working now? Does it depend on the operating system?
For the equivalent issue with upgrading pip in old Python installations, see Upgrading pip fails with syntax error caused by sys.stderr.write(f"ERROR: {exc}").
pip 21.0 dropped support for Python 2 and 3.5. The later versions require Python 3.6+. The syntax f"" is supported by Python 3.6+.
To install pip for Python 2.7 install it from https://bootstrap.pypa.io/pip/2.7/ :
- curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py
- python get-pip.py
- python -m pip install --upgrade "pip < 21.0"
The last command is to upgrade to the latest supported version.
For Python 2.7 the latest supported is currently pip 20.3.4.
For Python 3.6 install from https://bootstrap.pypa.io/pip/3.6/
For Python 3.5 install from https://bootstrap.pypa.io/pip/3.5/
For Python 3.4 install from https://bootstrap.pypa.io/pip/3.4/
For Python 3.4 the upgrade command is
python -m pip install --upgrade "pip < 19.2"
I solved it by firstly run
python -m pip install --upgrade "pip < 19.2"
and then
python -m pip install --upgrade "pip < 21.0".
It seems reinstall my pip 20.3.4 and the error disappreared!
This worked for me:On Mac:
Install pyenv as well as upgrade your python following the instructions on this here
Then in your terminal, if you run python -V and you still get the old version(system predefined version) showing:
To resolve this:
In your terminal run: alias python=python3
Then in your terminal execute python and you should now see that your system is using the python version you installed-:That is if you followed and completed the steps Here Correctly.
Restart your terminal(close/reopen):
Now you can finally install pip:
Read more about pip instalation steps [here][3]
1:In your terminal execute :$ python -m ensurepip --upgrade
2: Download the script, from https://bootstrap.pypa.io/get-pip.py.
But..**NB**: instead of navigating to the exact link provided,check out the available versions of pip here: pipversions
Select the latest version:
Then select getpip.py link to get the file and save it into your directory on your machine:
cd into the folder where you saved the newly downloaded script and execute:
Then execute:
python get-pip.py
Pip installed successfully:
For me python 3.5 on aws ec2 below worked
curl -O https://bootstrap.pypa.io/pip/3.5/get-pip.py
Then
sudo python3.5 get-pip.pyenter image description here
I have also tried all thing but my solution was download old get-pip version and install.
download: curl -O https://bootstrap.pypa.io/2.7/get-pip.py the file get-pip.py
install: python get-pip.py or python2 get-pip.py
enjoy
This is worked on Debian systems.
Edit: A better solution is always to install a Python version that is long supported. If at all you need to work with an older version - only then must one resort to the above workaround.
Uninstall existing pip on your machine
Run this cmd in ubuntu or any linux machine
curl https://bootstrap.pypa.io/pip/3.5/get-pip.py -o get-pip.py
python3 get-pip.py
It will work
I was just trying to download packages using pip in the terminal in pycharm and there was a notice from pip saying "You are using pip version 10.0.1, however, version 19.3.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command."
I ran the command but when I typed "pip -V" to check the version, it remained the same 10.0.1. And when I run the command, it says that pip is already up to date
How can solve this?
Your python and pip seem to point to different python versions. Check by typing which python or where python in the terminal.
To make sure they match, you can use
python -m pip install --upgrade pip (as you did) for upgrading
python -m pip install <package name> for installation
I did like this
pip install flake8
then, terminal says that it has already installed and it is in
.pyenv/versions/anaconda3-2.1.0/lib/python3.4/site-packages. But,I did like this
which flake8
then, terminal says nothing. Why? I couldn't install that ?
It appears that your pip is using your pyenv installed version of python from anaconda. With that in mind, you should ensure that python points to that as well and do python -m flake8. That will let you run flake8.
Flake8 does not control where it's executable is installed to, but as long as you use the same python as is being used by pip, then you will still be able to run it.