pip installing python packages for the wrong version - python

I'm trying to use pip to install some packages that I need, but I came across a problem. My default version of python is python3.10 but when I try using pip to install packages for it, it installes them for python3.8
This is the output of pip --version:
pip 22.1.2 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)
Is there a way to change this so that I can install packages for python 3.10?
When I try to run python3 -m pip --version I get:
/usr/local/bin/python3: No module named pip

Download get-pip.py file from any of the following options:
Download it manually from here.
Download it from terminal/cmd using: wget https://bootstrap.pypa.io/get-pip.py
Download it from terminal/cmd using: curl https://bootstrap.pypa.io/get-pip.py
Then run the command python3 get-pip.py, it will install pip in the python version invoked by python3(which is 3.10 as you have stated).
Install packages using command python3 -m pip install package_name

Since you've said you can call the desired python version with the command python3, it's best to call pip via
python3 -m pip
This ensures you're installing packages to the correct version (Dealing with multiple Python versions and PIP?).
To install pip if it's missing, you can use ensurepip (as per this answer)
python3 -m ensurepip
It's probably worth mentioning venv which lets you create a local python environment to keep your packages separate for different projects.

Related

How to install pip3 without upgrading Python version?

I'm trying to install software in kali that requires my Python version to be 3.6.9 or lower.
I also need to install pip to install requirements.
I have Python3.6.9 installed and when I run #apt-get install python3-pip
It also updates my Python version to 3.10
Is there a way to get pip installed without upgrading my python version?
If you are looking to install pip on to an existing python installation, which did not come with pip pre-installed, you can use the bootstrap script to that.
Like
curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py #or python3
If you want to update the pip version installed, then you can use
python -m pip install --upgrade pip

Installing python2 pyyaml

I have a legacy script that uses Python2 (which I can't modify). It imports module yaml. On older machines, this is satisfied using pip install pyyaml.
I'm using a newly built Ubuntu laptop which has had apt install python2 done. However, there is only a python3 version of pip available. The command python2 -m pip install pyyaml says there is no module named pip. I cannot do apt install python2-pip or anything like apt install python2-pyyaml or python2-yaml or similar as there are no such packages available any more. Is there an easy way I can install module yaml for python2 now that python2 is unsupported?
Just do a curl for the following to install pip for python2:
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
Then run
sudo python2 get-pip.py
You can then use the command pip2 --version tp check if pip is installed and for the correct version of python.

Python3 running on Mac but no Pip3?

I need to get pip3 running on my Mac terminal for a project. I have python3 installed, and I can run it, but when I try to run pip3 freeze, it says my command is not found.
I thought it would be automatically installed when I installed Python3. I tried to sudo install it, but it still didn't do anything. What can I do?
Besides brew install pip3, in case brew is not installed on your Mac, you can install pip3 via get_pip.py which can be found here. Assuming that python3 is already installed, cd to the directory where you saved get_pip.py and run the file with python3 get_pip.py. This should get pip3 installed on your machine.
On my MacBook Pro (10.13.5), which pip3 shows that it is located at /opt/local/bin/pip3 but it is a symlink to /opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin/pip3.
This is the location of python3 if you installed it via MacPorts. If you installed it with HomeBrew, then it would be /usr/local/Cellar/python/3.7.0/bin/pip3 (again, version might vary).
Finding pip3
What I would do if I were you is first find out where your pip3 actually is by either using locate or trying to manually find it by typing (Change 3.6 to whatever version you're on.) either:
$ /opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin/pip3 --version
or:
$ /usr/local/Cellar/python/3.7.0/bin/pip3 --version
You should see something like:
pip 9.0.3 from /opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (python 3.6)
Otherwise, use locate:
$ locate pip3
As a last resort, the slow find can also be useful:
$ sudo find / -name pip3
Build a Symlink
Then, make a symbolic link to that file in a path that is in your $PATH (again, ensure you replace the first path with the path to your actual pip3):
$ sudo ln -s /opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin/pip3 /opt/local/bin/pip3
Assuming you are using Python 3.4 or later in which pip is included by default, try the following command:
python3 -m pip freeze
When you use the -m command-line flag, python will search sys.path for the named module and execute its contents as the __main__ module. (more here)
This solution will allow you to use pip by python3 -m pip, but in order to use pip3 directly you can:
Install it via Homebrew:
brew install pip3
Install it with get-pip.py:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
You could try brew install pip3. Or check where pip is installed, that might point to Python 3's version.

How to install pip for a specific python version

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

How to install pip for Python 3 on Mac OS X?

OS X (Mavericks) has Python 2.7 stock installed. But I do all my own personal Python stuff with 3.3. I just flushed my 3.3.2 install and installed the new 3.3.3. So I need to install pyserial again. I can do it the way I've done it before, which is:
Download pyserial from pypi
untar pyserial.tgz
cd pyserial
python3 setup.py install
But I'd like to do like the cool kids do, and just do something like pip3 install pyserial. But it's not clear how I get to that point. And just that point. Not interested (unless I have to be) in virtualenv yet.
UPDATE: This is no longer necessary as of Python3.4. pip3 is installed as part of the general Python3 installation.
I ended up posting this same question on the python mailing list, and got the following answer:
# download and install setuptools
curl -O https://bootstrap.pypa.io/ez_setup.py
python3 ez_setup.py
# download and install pip
curl -O https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
Which solved my question perfectly. After adding the following for my own:
cd /usr/local/bin
ln -s ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/pip pip
So that I could run pip directly, I was able to:
# use pip to install
pip install pyserial
or:
# Don't want it?
pip uninstall pyserial
I had to go through this process myself and chose a different way that I think is better in the long run.
I installed homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
then:
brew doctor
The last step gives you some warnings and errors that you have to resolve. One of those will be to download and install the Mac OS X command-line tools.
then:
brew install python3
This gave me python3 and pip3 in my path.
pieter$ which pip3 python3
/usr/local/bin/pip3
/usr/local/bin/python3
Install Python3 on mac
1. brew install python3
2. curl https://bootstrap.pypa.io/get-pip.py | python3
3. python3
Use pip3 to install modules
1. pip3 install ipython
2. python3 -m IPython
:)
Here is my simple solution:
If you have python2 and python3 both installed in your system, the pip upgrade will point to python2 by default. Hence, we must specify the version of python(python3) and use the below command:
python3 -m pip install --upgrade pip
This command will uninstall the previously installed pip and install the new version- upgrading your pip.
This will save memory and declutter your system.
Image - How the upgrading of pip in Python3 works on MacOS
Plus:
when you install requests with python3, the command is:
pip3 install requests
not
pip install requests
brew install python3
create alias in your shell profile
eg. alias pip3="python3 -m pip" in my .zshrc
➜ ~ pip3 --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
To use Python EasyInstall (which is what I think you're wanting to use), is super easy!
sudo easy_install pip
so then with pip to install Pyserial you would do:
pip install pyserial
On Mac OS X Mojave python stands for python of version 2.7 and python3 for python of version 3. The same is pip and pip3. So, to upgrade pip for python 3 do this:
~$ sudo pip3 install --upgrade pip
Also, it's worth to mention that Max OSX/macOS users can just use Homebrew to install pip3.
$> brew update
$> brew install python3
$> pip3 --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
On MacOS 10.12
download pip: pip as get-pip.py
download python3: python3
install python3
open terminal: python3 get-pip.py
pip3 is available
pip is installed automatically with python2 using brew:
brew install python3
pip3 --version
simply run following on terminal if you don't have pip installed on your mac.
sudo easy_install pip
download python 3 here: python3
once you're done with these 2 steps, make sure to run the following to verify whether you've installed them successfully.
python3 --version
pip3 --version
For a fresh new Mac, you need to follow below steps:-
Make sure you have installed Xcode
sudo easy_install pip
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor
brew doctor
brew install python3
And you are done, just type python3 on terminal and you will see python 3 installed.
I had the same problem with python3 and pip3. Decision: solving all conflicts with links and other stuff when do
brew doctor
After that
brew reinstall python3
I'm using MacOS 11.6 and in my case I did two things;
Install Python 3 from https://www.python.org/downloads/macos/ clicking on first link Download macOS 64-bit universal2 installer from Stable Releases list
Create alias for Python3 running the following command on Terminal echo "alias python='/usr/bin/python3'" > ~/.bash_profile
After that open a new terminal and type python -V to check if the version of python 3 is enabled by default for your use so now you can use the command pip3 to install your packages like pip3 install somepackage
use port to install it, it is better than brew, in case you have an old machine.
sudo port install py38-pip

Categories

Resources