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
Related
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
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've tried to install virtualenv using sudo pip install virtualenv but it's not installing properly. This is what happens when I use sudo pip install virtualenv again and then try to get the version of it.
https://gyazo.com/0cbff8acaf8f4fdc505e53913739e28a
https://gyazo.com/9a5917157ac5c6ef44d49c2752f1e113
You need to add the folder containing virtualenv to your shell's path:
export PATH=$PATH:/path/to/folder/containing/virtualenv/
You could also create a symlink to the virtualenv file in /usr/bin or /usr/local/bin. These two folders are usually in the shell PATH by default:
ln -s /path/to/virtualenv /usr/local/bin/virtualenv
I tried to start virtualenv WITHOUT sudo but unfortunately it cannot find (Permission denied) /lib/python2.7/site-packages/easy_install.py. So I did:
sudo virtualenv name_env
The problem is that now pip is the global version (not inside pip):
which pip:
/usr/local/bin/pip
So I cannot install any package inside the environment.
If I start virtualenv without sudo:
virtualenv name_env
OSError: Command /Users/andrea/package_lambda/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error code 2
Any suggestion?
Don't use sudo just because you can!
I suggest you install another Python environment using brew, and then install pip, and subsequently virtualenv. This way, you'll substantially correct the underlying problem.
I would follow this method:
brew install pyenv
pyenv install 2.7.11
Or check the available versions through:
pyenv versions
This way, you can install different versions and switch between them as you wish, for instance:
pyenv global 2.7.11
And then you can install pip like so:
python -m easy_intall pip
and then install virtualenv like so:
python -m pip install virtualenv
As pouria mentioned, I believe it's a good idea to make sure you installed virtualenv using pip in the first place. I also agree that on OSX, using sudo should be rare.
As mentioned on a previous answer, you should also check that the files in the bin of your virtual env are correct.
I found the solution myself. I was using iterm instead of terminal (standard mac OS X). Using terminal I did:
sudo pip uninstall virtualenv
sudo pip install virtualenv
sudo cp /usr/local/bin/virtualenv /bin/virtualenv
Then I can create start a virtualenv:
virtualenv name_env
source name_env/bin/activate
To install python package on it I use:
sudo pip install --target=name_env/lib/python2.7/site-packages/ package name
I have the following file ~/.pydistutils.cfg with the contents
[install]
prefix=
temporarily removing this file fixed the issue for me (i had this file in place to address a different issue)