How can I install packages? - python

I can't install a package with the pip or pip3 command and I can't install it from the Python Interpreter in PyCharm too. I can't tap on the '+' at the Python Interpreter in PyCharm.
I get this error:
pip command not found

Here is what you can try.
Lets check python installation.
C:\Users\User>python --version
Python 3.10.5
C:\Users\User>
If you get the version as 3.x, then we are good, else goto your python installation directory and copy its path and then add it to your environment variable PATH.
Check PIP available or not.
C:\Users\User>pip --version
pip 22.3 from C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pip (python 3.10)
C:\Users\User>
if above didn't work then add pip path to PATH environment variable which would be something similar to above output.
Now we are ready to install any package
Just do pip install package-name
for testing, you can try:
pip install numpy
If it still throws error, try below one
python -m pip install numpy
if it still throws error, then you might need to clean your python installation.

3 commands
sudo apt update
sudo apt install python3-pip
pip3 install <package_name>
or maybe
sudo apt install <package_name> -y

It looks like you don't have pip installed on $PATH. The following command will run pip without any adjustments to $PATH:
python3 -m pip install <some_module>
Pay attention to the -m, this stands for modules and runs the pip program inside the python3 interpreter (I don't know exact definition here, if anyone wishes to correct me I will update the answer)
However, if this doesn't work then you may not have pip installed, and can be installed by running:
python3 -m ensurepip --upgrade
Then, reload your shell via the following (replace bash with your shell):
exec bash
Running pip --version should now work

Related

how to install Pip3 on windows 10?

I installed Python 3.10 today but when I try to run pip or pip3, the command prompt gives me an error. I tried following the instructions that the top answer in this question said. My complete path to the python interpreter is this:
C:\Users\User\AppData\Local\Microsoft\WindowsApps\python3.exe
In the WindowsApps directory, I'm supposed to have a Scripts folder. Strangely enough, I don't. Can someone please help me?
Check if pip3 is already installed
pip3 -v
if it is installed the output should be like that
C:\Python38\python.exe -m pip <command> [options]
Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
...
...
Pip3 Upgrade
python -m pip3 install --upgrade pip
Pip3 Downgrade
python -m pip3 install pip==19.0
You can try python -m pip to use pip if it is installed.
If pip is not installed, you can always use python -m ensurepip --upgrade to install pip for your python installation.
Take a look at the following post
How can I install pip on Windows?
py -3 -m ensurepip

cant install python packages

I have multiple versions of python install in my linux.
python
python2.7
python2.7-config
python2-config
python2-jsonschema
python2-pbr
python3
python3.4
python3.4m
python3.6
python3.6-config
python3.6m
python3.6m-config
python3-config
python3m
python3m-config
python-argcomplete-check-easy-install-script
python-argcomplete-tcsh
python-config
python-faraday
I installed quandl package using pip. it's installed but when I run the code it says there is no module as quandl. I think its related to multiple versions of python.how can I uninstall these versions and which one i should uninstall and how can i install packages and run my code without any worry! I am a beginner so please help me.
in Linux,if you are using Global environment You should use python3.x for all command-line operations as in python3.4, python3.6 or pip3.4, pip3.6 when compiling so it installs to specified version.
for your problem to find the installed module run:
pip3.4 list pip3.6 list and pip 2.7 list and find quandl in them.
If it is not in the required version of yours, run: pip[your-version] install quandl
First, sure that pip3 is installed or install it.
ubuntu: sudo apt install python3-pip --upgrade
now, install your package with pip3 instead of pip:
pip3 install quandl
I hope it will work:)
EDITED:
with this code, you create a virtualenv and run your script with it.
pip3 install virtualenv
virtualenv -p python3.x venv //3.x will be version you want
source venv/bin/activate
pip install quandl, {and what else you want}
python script.py
for deactivating virtualenv, just run this in commandLine:
deavtivate

Pip command not found in bash - OSX [duplicate]

I downloaded pip and ran python setup.py install and everything worked just fine. The very next step in the tutorial is to run pip install <lib you want> but before it even tries to find anything online I get an error "bash: pip: command not found".
This is on Mac OS X. I'm assuming there's some kind of path setting that was not set correctly when I ran setup.py. How can I investigate further? What do I need to check to get a better idea of the exact cause of the problem?
EDIT: I also tried installing Python 2.7 for Mac in the hopes that the friendly install process would do any housekeeping like editing PATH and whatever else needs to happen for everything to work according to the tutorials, but this didn't work. After installing, running 'python' still ran Python 2.6 and PATH was not updated.
Why not just do sudo easy_install pip or if this is for python 2.6 sudo easy_install-2.6 pip?
This installs pip using the default python package installer system and saves you the hassle of manual set-up all at the same time.
This will allow you to then run the pip command for python package installation as it will be installed with the system python. I also recommend once you have pip using the virtualenv package and pattern. :)
2020 Update:
For current Debian/Ubuntu, use
apt-get install python3-pip
to install pip3.
Old 2013 answer (easy_install is now deprecated):
Use setuptools to install pip: sudo easy_install pip
(I know the above part of my answer is redundant with klobucar's, but I can't add comments yet), so here's an answer with a solution to sudo: easy_install: command not found on Debian/Ubuntu: sudo apt-get install python-setuptools
Also, for python3, use easy_install3 and python3-setuptools.
For Python 3, use apt-get install python3-pip.
First of all: try pip3 instead of pip. Example:
pip3 --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
pip3 should be installed automatically together with Python3.x. The documentation hasn't been updated, so simply replace pip by pip3 in the instructions, when installing Flask for example.
Now, if this doesn't work, you might have to install pip separately.
Update: A more reliable modern way to access the right pip install for the right python install is to use the syntax python -m pip.
Original Answer
pip would install itself into the bin of your python installation location. It also should create a symlink to some more common location like /usr/local/bin/pip
You can either edit your ~/.profile and update your PATH to include /Library/Frameworks/Python.framework/Versions/2.6/bin, or you could create a symlink to it in a place that you know is in your path.
If you do: echo $PATH, you should see the paths currently being searched. If /usr/local/bin is in your PATH, you can do:
ln -s /Library/Frameworks/Python.framework/Versions/2.6/bin/pip /usr/local/bin
I would opt for adding the python bin to your $PATH variable.
I encountered this problem having downloaded python 3.x.x and trying to install awscli - pip: command not found.
Whilst following the instructions for downloading the AWS client, I changed
pip install awscli
to
pip3 install awscli
which ran the correct version.
I've made an alias on my machine to run python3 whilst typing python, which would normally run the system version 2.7. I'm not sure this is a good idea now. I think I'll just type in the commands as they intended them to be.
Check out How to Install Pip article for more information.
As of 2019,
Download get-pip.py provided by https://pip.pypa.io using the following command:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Run get-pip.py using the following command:
sudo python get-pip.py
After you done installing, run this command to check if pip is installed.
pip --version
Remove get-pip.py file after installing pip.
rm get-pip.py
Install Python latest version as given here
It has many download links like numpy and scipy
Then go to terminal and enter following command:-
sudo easy_install pip
For Python install packages check this
Requirements for Installing Packages
This section describes the steps to follow before installing other Python packages.
Install pip, setuptools, and wheel If you have Python 2 >=2.7.9 or
Python 3 >=3.4 installed from python.org, you will already have pip
and setuptools, but will need to upgrade to the latest version:
On Linux or OS X:
pip install -U pip setuptools On Windows:
python -m pip install -U pip setuptools If you’re using a Python
install on Linux that’s managed by the system package manager (e.g
“yum”, “apt-get” etc…), and you want to use the system package manager
to install or upgrade pip, then see Installing pip/setuptools/wheel
with Linux Package Managers
Otherwise:
Securely Download get-pip.py 1
Run python get-pip.py. 2 This will install or upgrade pip.
Additionally, it will install setuptools and wheel if they’re not
installed already.
I spent ages going through all the answers on this page but found the one that worked for me in the comments of the OP question by s-walsh
The answer is to use pip3:
$ pip3 install <name-of-install>
Installing using apt-get installs a system wide pip, not just a local one for your user. Try this command to get pip running on your system ...
$ sudo apt-get install python-pip python-dev build-essential
Then pip will be installed without any issues and you will be able to use "sudo pip...".
Most of the methods to install PIP are deprecated. Here is the latest (2019) solution. Please download get-pip script
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Run the script
sudo python get-pip.py
Latest update 2021.
In Ubuntu 20 64bit works perfectly
Installation of python3
sudo apt install python3
Pip Installation
sudo apt install python3-pip
Add following alias in $HOME/.bash_aliases in some cases file may be hidden.
alias pip="/usr/bin/python3 -m pip "
Refresh current terminal session.
. ~/.profile
check pip usage: pip
Install a package: pip install {{package_name}}
extra info
to get Home path
echo $HOME
you will get your home path.
To solve:
Add this line to ~/.bash_profile:
export PATH="/usr/local/bin:$PATH"
In a terminal window, run
source ~/.bash_profile
It might be the root permission. I tried exit root login, and use
sudo su -l root
pip <command>
install Homebrew, open Terminal or your favorite OSX terminal emulator and run
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
insert the Homebrew directory at the top of your PATH environment variable. You can do this by adding the following line at the bottom of your ~/.profile file
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
Now, we can install Python 2.7:
$ brew install python
Get pip repository:
$ git clone https://github.com/pypa/pip
install pip:
$sudo easy_install pip
python install it by default but if not install you can install it manual use following cmd (for linux only )
for python3 :
sudo apt install python3-pip
for python2
sudo apt install python-pip
hope its help.
If you are running Python 3.5, run the following terminal command:
sudo pip3 install -U nltk
Any other pip commands in terminal would be similar:
pip3 install --upgrade pip
sudo pip3 install -U numpy ::
It solved my problem by using
sudo easy_install pip
Solved this by upgrading python 3 brew upgrade python:
Now i can just do:
pip3 install <package>
==> python
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have
Based on this stackoverflow answer and some of the answers on this thread, I have created an alias in the rc file:
alias pip="python3 -m pip"
There seem to be many different answers to this question but this seems to be the best-practice approach.
Avoiding sudo:
python <(curl https://bootstrap.pypa.io/get-pip.py) --user
echo 'export "PATH=$HOME/Library/Python/2.7/bin:$PATH"' >> ~/.bash_profile
From:
http://www.pip-command-not-found.com
CentOS 7 users can just use:
yum install python-pip
Also recommend using virtualenv if you're using pip. It can be added in the same way:
yum install python-virtualenv
assuming you have internet see:
https://pip.pypa.io/en/stable/installing/
basically run:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
and
python get-pip.py
Try using this. Instead of zmq, we can use any package instead of zmq.
sudo apt-get install python3-pip
sudo apt-get update
python3 -m pip install zmq
I was was not able to install this zmq package in my docker image because of the same issue i was getting. So tried this as another way to install and it worked fine for me.
To overcome the issue bash: pip: command not found in Mac
Found two versions on Mac 1 is 2.7 and the other is 3.7
when I say sudo easy_install pip, pip got installed under 2.7
when I say sudo easy_install-3.7 pip, pip got installed under 3.7
But, whenever I would require to do pip install , I wanted to install the package under python3.7, so I have set an alias (alias pip=pip3) in .bash_profile.
so now, whenever I do pip install <package_name>, it gets installed under python3.7
(Context: My OS is Amazon linux using AWS. It seems similar to RedHat but it's stripped down a bit, it seems.)
Exit the shell, then open a new shell. The pip command now works.
That's what solved the problem at this location.
You might want to know as well: The pip commands to install software then needed to be written like this example (jupyter for example) to work correctly on my system:
pip install jupyter --user
Specifically, note the lack of sudo, and the presence of --user
Would be real nice if pip docs had said anything about all this, but that would take typing in more characters I guess.
Not sure why this wasnt mentioned before, but the only thing that worked for me (on my NVIDIA Xavier) was:
sudo apt-get install python3-pip
(or sudo apt-get install python-pip for python 2)
apt -y -qq install python3 python3-pip
ln -s /usr/bin/python3 /usr/bin/python
ln -s /usr/bin/pip3 /usr/bin/pip
What I did to overcome this was sudo apt install python-pip.
It turned out my virtual machine did not have pip installed yet. It's conceivable that other people could have this scenario too.
The updated command for installing pip3 is :
sudo apt-get install python3-pip
The problem seems that your python version and the library yoıu want to install is not matching versionally. Ex: If Django is Django3 and your python version is 2.7, you may get this error.
"After installing is running 'python' still ran Python 2.6 and PATH was not updated."
1- Install latest version of Python
2- Change your PATH manually as python38 and compare them.
3- Try to reinstall.
I solved this problem as replacing PATH manually with the latest version of Python.
As for Windows: ;C:\python38\Scripts

how to use python2.7 pip instead of default pip

I just installed python 2.7 and also pip to the 2.7 site package.
When I get the version with:
pip -V
It shows:
pip 1.3.1 from /usr/lib/python2.6/site-packages (python 2.6)
How do I use the 2.7 version of pip located at:
/usr/local/lib/python2.7/site-packages
There should be a binary called "pip2.7" installed at some location included within your $PATH variable.
You can find that out by typing
which pip2.7
This should print something like '/usr/local/bin/pip2.7' to your stdout. If it does not print anything like this, it is not installed. In that case, install it by running
$ wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
$ sudo python2.7 get-pip.py
Now, you should be all set, and
which pip2.7
should return the correct output.
An alternative is to call the pip module by using python2.7, as below:
python2.7 -m pip <commands>
For example, you could run python2.7 -m pip install <package> to install your favorite python modules. Here is a reference: https://stackoverflow.com/a/50017310/4256346.
In case the pip module has not yet been installed for this version of python, you can run the following:
python2.7 -m ensurepip
Running this command will "bootstrap the pip installer". Note that running this may require administrative privileges (i.e. sudo). Here is a reference: https://docs.python.org/2.7/library/ensurepip.html and another reference https://stackoverflow.com/a/46631019/4256346.
as noted here, this is what worked best for me:
sudo apt-get install python3 python3-pip python3-setuptools
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
pip has now dropped support for python2, therefore you can't use python2 pip
You can't find python2-pip in apt-get anymore, and you won't get pip when installing python2 from source
You can still install python modules using apt-get. To install a python prepend ‘python-’ to the module name
apt-get install python-six # install six

How do I update/upgrade pip itself from inside my virtual environment?

I'm able to update pip-managed packages, but how do I update pip itself? According to pip --version, I currently have pip 1.1 installed in my virtualenv and I want to update to the latest version.
What's the command for that? Do I need to use distribute or is there a native pip or virtualenv command? I've already tried pip update and pip update pip with no success.
pip is just a PyPI package like any other; you could use it to upgrade itself the same way you would upgrade any package:
pip install --upgrade pip
On Windows the recommended command is:
python -m pip install --upgrade pip
The more safe method is to run pip though a python module:
python -m pip install -U pip
On windows there seem to be a problem with binaries that try to replace themselves, this method works around that limitation.
In my case my pip version was broken so the update by itself would not work.
Fix:
(inside virtualenv):easy_install -U pip
I tried all of these solutions mentioned above under Debian Jessie. They don't work, because it just takes the latest version compile by the debian package manager which is 1.5.6 which equates to version 6.0.x. Some packages that use pip as prerequisites will not work as a results, such as spaCy (which needs the option --no-cache-dir to function correctly).
So the actual best way to solve these problems is to run get-pip.py downloaded using wget, from the website or using curl as follows:
wget https://bootstrap.pypa.io/get-pip.py -O ./get-pip.py
python ./get-pip.py
python3 ./get-pip.py
This will install the current version which at the time of writing this solution is 9.0.1 which is way beyond what Debian provides.
$ pip --version
pip 9.0.1 from /home/myhomedir/myvirtualenvdir/lib/python2.7/dist-packages (python 2.7)
$ pip3 --version
pip 9.0.1 from /home/myhomedir/myvirtualenvdir/lib/python3.4/site-packages (python 3.4)
In case you are using venv any update to pip install will result in upgrading the system pip instead of the venv pip. You need to upgrade the pip bootstrapping packages as well.
python3 -m pip install --upgrade pip setuptools wheel
for windows,
go to command prompt
and use this command
python -m pip install -–upgrade pip
Dont forget to restart the editor,to avoid any error
you can check the version of the pip by
pip --version
if you want to install any particular version of pip , for example version 18.1 then use this command,
python -m pip install pip==18.1
pip install --upgrade pip
In UBUNTU 18.04 I got the following error when I execute the above command:
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/bin/pip'
Consider using the `--user` option or check the permissions.
The below command solves my problem:
pip install --upgrade pip --user
Upgrading pip using 'pip install --upgrade pip' does not always work because of the dreaded cert issue: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version
I like to use the one line command for virtual envs:
curl https://bootstrap.pypa.io/get-pip.py | python -
Or if you want to install it box wide you will need
curl https://bootstrap.pypa.io/get-pip.py | sudo python -
you can give curl a -s flag if you want to silence the output when running in an automation script.
To get this to work for me I had to drill down in the Python directory using the Python command prompt (on WIN10 from VS CODE). In my case it was in my AppData\Local\Programs\Python\python35-32 directory. From there now I ran the command...
python -m pip install --upgrade pip
This worked and I'm good to go.
For linux
python3 -m pip install --upgrade pip
For windows:
Type Command Prompt in the Windows search box
In the Command Prompt, type cd\
Press Enter, and you’ll see the drive name C:\>
Locate your Python application path, which is the folder where you originally installed Python
Here is an example of a Python application path:
C:\Users\Ron\AppData\Local\Programs\Python\Python39
Once you retrieved the Python application path, type the following command in the Command Prompt:
cd followed by your Python application path
For our example:
C:\>cd C:\Users\Ron\AppData\Local\Programs\Python\Python39
Press Enter
Type python -m pip install --upgrade pip and press Enter
In my case this worked from the terminal command line in Debian Stable
python3 -m pip install --upgrade pip
Open Command Prompt with Administrator Permissions, and repeat the command:
python -m pip install --upgrade pip
pip version 10 has an issue. It will manifest as the error:
ubuntu#mymachine-:~/mydir$ sudo pip install --upgrade pip
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
ImportError: cannot import name main
The solution is to be in the venv you want to upgrade and then run:
sudo myvenv/bin/pip install --upgrade pip
rather than just
sudo pip install --upgrade pip
I was in a similar situation and wanted to update urllib3 package.
What worked for me was:
pip3 install --upgrade --force-reinstall --ignore-installed urllib3==1.25.3
On my lap-top with Windows 7 the right way to install latest version of pip is:
python.exe -m pip install --upgrade pip
First, do this:
sudo apt install python3-pip python-setuptools-doc
Then, as a non-root user (NEVER, never run pip* as root!):
# N.B. bash shell works for this, I have never tested with other shells!
. ....your_virtualenv_folder/bin/activate
pip3 install -U pip
Note: -U is a synonym for --upgrade, as far as I know.
I had installed Python in C:\Python\Python36 so I went to the Windows command prompt and typed cd C:\Python\Python36 to get to the right directory. Then entered the python -m install --upgrade pip all good!
Single Line Python Program
The best way I have found is to write a single line program that downloads and runs the official get-pip script. See below for the code.
The official docs recommend using curl to download the get-pip script, but since I work on windows and don't have curl installed I prefer using python itself to download and run the script.
Here is the single line program that can be run via the command line using Python 3:
python -c "import urllib.request; exec(urllib.request.urlopen('https://bootstrap.pypa.io/get-pip.py').read())"
This line gets the official "get-pip.py" script as per the installation notes and executes the script with the "exec" command.
For Python2 you would replace "urllib.request" with "urllib2":
python -c "import urllib2; exec(urllib2.urlopen('https://bootstrap.pypa.io/get-pip.py').read())"
Precautions
It's worth noting that running any python script blindly is inherently dangerous. For this reason, the official instructions recommend downloading the script and inspecting it before running.
That said, many people don't actually inspect the code and just run it. This one-line program makes that easier.
I had a similar problem on a raspberry pi.
The problem was that http requires SSL and so I needed to force it to use https to get around this requirement.
sudo pip install --upgrade pip --index-url=https://pypi.python.org/simple
or
sudo pip-3.2 --upgrade pip --index-url=https://pypi.python.org/simple/
Head to your command prompt and type the following:
python -m pip install --upgrade pip
While updating pip in virtual env use full path in python command
Envirnments folder struture
myenv\scripts\python
h:\folderName\myenv\scripts\python -m pip install --upgrade pip
Very Simple. Just download pip from https://bootstrap.pypa.io/get-pip.py . Save the file in some forlder or dekstop. I saved the file in my D drive.Then from your command prompt navigate to the folder where you have downloaded pip. Then type there
python -get-pip.py
In linux
I will update with this code
sudo -H pip3 install --upgrade pip

Categories