How can I use pip in oh-my-zsh? I was trying to install nltk through pip, but it told me zsh: command not found: pip. When I check plugins under .oh-my-zsh/custom/plugins, there is a folder named pip. I don't know what the problem is.
Edit:
$ echo $PATH
/home/xxx/bin:/usr/local/bin:/home/xxx/bin:/home/xxx/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ type pip
pip is an alias for noglob pip
Maybe you have installed both python2 and python3. python3 may have been installed later.
You may try to use pip3 instead of pip.
First, input the command:
pip3 -V
If you see the version, the pip3 can be used.
Then you can input command line to install nltk:
pip3 install nltk
I got a way to help you use pip in zsh. We can use nano to edit files. In nano, ctrl+X to save and exit
In the ~ directory, input the command:
nano .bash_profile
You may see some codes like:
# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
Copy them and paste them to the end of .zshrc file by using command:
nano .zshrc
Then input the command:
pip -V
If you see the version, pip can be used.
In case you do
which pip
and it doesn't show the path, just do
which pip3
This will print the path which is /usr/local/bin/pip3
Then do open ~/.zshrc or nano ~/.bash_profile.
Make alias for pip like:
alias pip=/usr/local/bin/pip3
N.B: You copy that line above and paste in your .zshrc file.
After do source ~/.zshrc and close .zshrc
For me it's working to do
python -m pip install [package_name]
instead of
pip install [package_name]
If you installed python3.x, you should run with pip3(not pip)
So you are using oh-my-zsh framework for zsh or Z shell.
First, try the command:
pip3 -V
If you get something like this below, that means you have the pip3 package already and must be having python3 as well.
pip 22.0.4 from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip (python 3.10)
Then edit your .zprofile instead of .bashprofile as you are using zsh. This is the command.
nano ~/.zprofile
Then it should have the two alias like this.
# Setting PATH for Python 3.10
# The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.10/bin:${PATH}"
export PATH
alias python=python3
alias pip=pip3
Make sure you save it. Exit and Re-open you terminal. Type the command:
pip -V
It should have the same result as the pip3 -V like this:
❯ pip -V
pip 22.0.4 from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip (python 3.10)
Then you can use pip or pip3 interchangeably for installing your nltk package like this.
pip install nltk
I'm on MacOS and use ZSH. It seems pip 2.7 can't be found, although it is installed. I believe my paths to "pip" are linked wrong (I also have python3 and pip3 installed via brew).
To get around the issue I created an alias. If you don't have an .aliases file, create one in your homedir. Then open the file:
nano ~/.aliases
and add:
## PIP for python2.7 ##
alias pip="python -m pip "
You need to tell ZSH to pick up the alias file (assuming you don't have this setup already). Open your .zshrc:
nano ~/.zshrc
The add the following near the bottom of the file:
[ -f "$HOME/.aliases" ] && source "$HOME/.aliases"
From the terminal, run:
source ~/.zshrc
Or quit your terminal and reopen it.
Now you can run:
pip install <command>
Edit your rc file:
vim ~/.zshrc
Find the config plugins and delete the pip entry.
In a new terminal:
which pip
This will show you the real path of pip
If you're running into this issue, it probably is due to versioning complications. Python 2 versus Python 3 on your OS may be resolving unexpectedly. Below is a quick workaround to get you to functioning behavior.
Try using the below for Python 2:
python -m pip install <command>
Try using the below for Python 3:
pip3 install <command>
In my case my OS was Ubuntu 20.04 and the pip doesn't come with python.
So, i've installed pip through the command
sudo apt install python3-pip
and I'm done.
To ensure run pip -V or pip3 -V
My pip script is missing for some reason, so I have to install it.
$ python -m ensurepip --upgrade
More methods can be found here:pip installation
You should consider upgrading.
Enter this in your terminal
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10 -m pip install --upgrade pip
and then...
Type: pip -V
Related
I recently switched from bash to zsh (MacOS). I haven't used pipenv since the switch. Now when I run any pipenv command I get the following error:
$ pipenv install
zsh: /usr/local/bin/pipenv: bad interpreter: /usr/local/opt/python/bin/python3.7: no such file or directory
I use pyenv for Python dependency management:
$ which python
/Users/ryan.payne/.pyenv/shims/python
My default python version is 3.7.3:
$ pyenv versions
system
2.7.16
3.6.8
* 3.7.3 (set by /Users/ryan.payne/.pyenv/version)
It seems like pipenv is not using my pyenv version of Python. How do I get pipenv working again?
You don't need to uninstall anything. Simply change the interpreter at /usr/local/bin and have your current python path in pyenv handy:
type python3
copy the path
vi /usr/local/bin/pipenv
It will look something like this:
Once it's changed, you will probably have to download pipenv again. Don't worry, your env is fine.
pip install pipenv
Go play in your env
I had this same error with awscli. The solution was to install python#3.7 via homebrew and then cp that installation into the directory awscli expected.
brew install python#3.7
cp -r /usr/local/opt/python#3.7/bin/python3.7 /usr/local/opt/python/bin/python3.7
Run in terminal:
brew install python3 && cp /usr/local/bin/python3 /usr/local/bin/python
After brew installation, sometimes it may not work.
Depending on whether you tried to install other python versions, the links might not be working any more, and therefore running the command
brew install python3 && cp /usr/local/bin/python3 /usr/local/bin/python
Might give an error as below
Error: Could not symlink bin/2to3
Target /usr/local/bin/2to3
already exists.
Try to remove the file 2to3
rm '/usr/local/bin/2to3'
and run the above code again
Alternatively, you can force the linkage
brew link --overwrite python#<version>
but you can first see the files that will be deleted by this forced linking using the command
brew link --overwrite --dry-run python#<version>
I hope this gives more light
If you installed pipenv with pipenv with pipx, then you can reinstall pipenv via pipx reinstall pipenv which should detect any top level changes in your python environment.
I am trying to install pip3. I ran brew install python3 which installed python3 correctly. I also ran brew post install python3 as I found on this site.
Now, I enter which pip3
and get /usr/local/bin/pip3
And when I run pip3
I get this message: -bash: /anaconda3/bin/pip3: No such file or directory
How do I completely remove anaconda from my computer AND install pip3 from here? I deleted the anaconda application, removed the PATH from nano ~/.bash_profile. and emptied the trash
EDIT: FIXED USING hash -r
are you running pip install command in conda environment
If you are running it in conda environment First deactivate it
Use
source deactivate
Waiting on my rep to hit 50.
Maybe an answer:
what is the output of? Checking to see if its a link
ls -la /usr/local/bin/pip3
Also look at your path
export | grep PATH
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.
I am trying to download pip onto my mac by following the instructions on the pip installation guide and I am coming up with this error after running the following command
$python get-pip.py
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/
MacOS/Python: can't open file 'get-pip.py': [Errno 2] No such file or directory
This is happening after I download the 'get-pip.py' doc as the instructions suggest. Do I need to put this file in a certain location before I continue? I am relatively new to downloading programs through the terminal.
Thanks for the help!
It is recommended (highly) that you NOT use the version of Python that ships with your Mac. Instead use HomeBrew and install a "custom" version of Python (usually the latest). Then proceed to use virtualenv and optionally virtualenvwrapper
Prerequisites:
First, install Xcode from the App Store (it's FREE).
Install HomeBrew:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
Install Python:
brew install python
This will install pip for you as well in /usr/local/bin/.
Install virtualenv:
pip install virtualenv
virtualenv Basic Usage:
virtualenv /path/to/my/env
cd /path/to/my/env
source ./bin/activate
# hack on your python project
deactivate # to go back to your normal shell
Please follow instructions for virtualenv for more details.
virtualenvwrapper is also really convenient and worthwhile learning.
Update :
More explanation at #dval 's comment
$ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
and then execute
$ python get-pip.py
None of the above solutions worked for me, so I decided to straight out clean install Python 3.6 from the downloads page at python.org.
After you have completed the Python installer, go into Terminal and type in:
curl -O https://bootstrap.pypa.io/get-pip.py
Wait for the download to complete and then type in:
python3 get-pip.py --user
Then for your pip commands you will use 'pip3'. For example:
pip3 install awsebcli --upgrade --user
After python and pip have been installed they should be in your user Library. So update your PATH in terminal like so:
export PATH=~/Library/Python/3.6/bin:$PATH
I have a bash_profile shell so I also ran the following command in terminal to load script into my current session:
source ~/.bash_profile
After this, verify that your pip installed component was successful.
For example:
eb --version
See AWS for the above reference.
Curl did not work for me. I had to use "wget".
$ wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
and then execute
$ python get-pip.py
After upgrading to OSX Mavericks, I am getting this message in the terminal:
/usr/bin/python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenv has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.
Try reinstalling pip and then reinstalling virtualenvwrapper (I had to go through these steps after upgrading to Mavericks):
$ sudo easy_install pip
$ sudo pip install --upgrade virtualenvwrapper
Re-arrange the export order so that the python path is placed before the virtualenv commands in your .bash_profile file.
# python path
export PATH=/usr/local/bin:$PATH
# needed for virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
Try edit .bash_profile file
# Home brew
export PATH=/usr/local/bin:$PATH
# virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
I wouldn't recommend running pip with sudo. This was my solution for the same problem (after upgrading to Mavericks).
In essence, uninstall any virtualenv and brewed Python you had before (use which <command> to check that you removed everything except the system Python in /usr/bin/python) and cleanly install them once again:
brew install python --with-brewed-openssl
# Open a new terminal tab now (to access /usr/local/bin/python)
pip install virtualenv
pip install virtualenvwrapper
pip install --upgrade virtualenvwrapper will fix the issue but never used sudo pip this will change system-wide. If pip throws permission errors without sudo then you should fix those and then try only with pip install <--upgrade> $(package).
I rather suggest install homebrew and then install pip using brew install pip which will install latest stable version of pip for you.
Install homebrew and then run brew doctor . If there are any warnings fix those(actually brew will tell you how to fixed those).
You may need to remove system-wide python comes with Mac and use brew to install required versions. Use this to remove system-wide python
Use brew install python or/and brew install python3 to install required python version/s.
Finaly run pip install --upgrade virtualenvwrapper
Now on never use sudo pip only use pip.
I had the same problem with MacOS High Sierra. I was able to fix it with these lines in my .bash_profile file:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Code
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
You just need to configure the path properly. Run the following commands in the terminal:
which python
Output -
/usr/bin/python
which virtualenvwrapper.sh
Output -
/usr/local/bin/virtualenvwrapper.sh
echo $VIRTUALENVWRAPPER_PYTHON
/usr/local/bin/python
So as you can see that the variable $VIRTUALENVWRAPPER_PYTHON is pointing towards the wrong python path. So we need to reset the path of variable $VIRTUALENVWRAPPER_PYTHON.
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
now run the following the command:
source /usr/local/bin/virtualenvwrapper.sh
Running these two commands helped me get rid of it (had done a software update on macOS High Sierra)
$ sudo easy_install pip
$ sudo pip install --upgrade virtualenvwrapper
Firstly Cross-verify PATH in .bashrc with following commands:
which virtualenv
which virtualenvwrapper.sh
output of:
echo $VIRTUALENVWRAPPER_PYTHON
and
which python3
should be same
which is
/usr/bin/python3
Configure the path accordingly to above results
export WORKON_HOME=~/.virtualenvs
export MY_PROJECT=~/my_proj
export VIRTUALENVWRAPPER_WORKON_CD=1
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV='result of which virtualenv'
source 'result of which virtualenvwrapper.sh'
if after verifying path still INITIALIZATION HOOK ERROR REMAINS.
Then, In source left everthing as it is just replace virtualenvwrapper.sh with virtualenvwrapper_lazy.sh
Then it should work