As I understood, I have two versions of python 2.7 installed on my machine. One is located in /usr/bin and another one is in /usr/local/bin. When I type python in the shell, it calls one in /usr/local/bin, and it doesn't have access to all the packages installed using apt-get and pip. I have tried to set up an alias, but when I type sudo python it still calls one in /usr/local/bin. I want to always use one in /usr/bin, since I have all the packages there. How do I do that?
From what I understood,
You have two version of python. One is in /usr/local/bin/python
and another is in /usr/bin/python.
In your current configuration default python ->
/usr/local/bin/python
You want to use the one that is in /usr/bin.
Update your ~/.bashrc and append this line at the end
alias python=/usr/bin/python
Then open a new terminal. Or do source ~/.bashrc in the current terminal
Run which python to see the location of the python executable. It will show you /usr/bin/python
Also, if you want to get packages in your current python (i.e. /usr/local/bin/python) you can use pip with that particular python version.
Find pip location using which pip
Assuming pip location is /usr/local/bin/pip
/usr/local/bin/python /usr/local/bin/pip install
you can easily have two python version in your machine.
But first I recommend to install the Anaconda package.
And then you can create an environment with python 3 version
conda create --name test_env python=3 numpy pandas
In order to activate it, you need to write in your terminal
source activate test_env
More info here:
https://conda.io/docs/using/envs.html
when i echo $PATH i receive /Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Users/me/.rvm/bin
I feel like this is too long of a path and is confusing things. I seem to have many of the same files / sym links that are unnecessary. I downloaded python 3 via Homebrew but Idle did not work so I downloaded Python 3 from the official site as well which may be confusing things.
I have other modules downloaded in the Cellar via Homebrew.
How can I get Pip3 to always install into the Cellar path? Path being used in PyCharm is /usr/local/Cellar/python3/3.6.0_1/Frameworks/Python.framework/Versions/3.6/bin/python3.6
bash_profile.txt shows:
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
eval $(/usr/libexec/path_helper -s)
# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
export PATH="/usr/local/bin:$PATH"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
##
# Your previous /Users/me/.bash_profile file was backed up as /Users/gf/.bash_profile.macports-saved_2017-03-15_at_18:43:29
##
# MacPorts Installer addition on 2017-03-15_at_18:43:29: adding an appropriate PATH variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
# Finished adapting your PATH environment variable for use with MacPorts.
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
Looks like you have a lot going wrong here. Let's see if we can fix this.
/Library/Frameworks/Python.framework/Versions/3.6/bin is appearing in your $PATH twice. Open ~/.bash_profile in a text editor and remove one of them. I'd recommend actually removing the /Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin at the beginning, because Homebrew has already linked python3 and pip3 into /usr/local/bin for you, which would be third in your path if you remove those two paths.
/Library/Frameworks/Python.framework/Versions/2.7/bin can also be removed from your $PATH; both python (2.7) and pip (for Python 2.7) are linked in /usr/bin, which is the very next thing in your $PATH.
As you noted, installing Python 3 from the website as well has confused things. The path that Pycharm is using is correct; that's Homebrew's Python 3.6 folder. The Python 3.6 installation in /Library can be deleted if you want to use Homebrew's only.
If you really need IDLE (not sure why you would, since Pycharm is better anyway), you can run brew linkapps python3 to link the ones from Homebrew's Python 3.6 to /Applications.
Hopefully that should fix your issues!
I just installed python 3.5 from the official python website. It installed on my computer and it install on my computer under:
/Library/Frameworks/Python.framework/Versions/3.5
However, I am trying to run virtualenv and it will take me to this error message when I try to create a new virtual environment.
-bash: /Users/me/anaconda/bin/virtualenv: No such file or directory
I removed Anaconda from my computer but still unable to create a virtual environment under my python 3.5 path even though it has installed.
Here is my bash_profile.
# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH
# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH
# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH
##
# Your previous /Users/lewismenelaws/.bash_profile file was backed up as /Users/lewismenelaws/.bash_profile.macports-saved_2015-02-25_at_15:58:24
##
# MacPorts Installer addition on 2015-02-25_at_15:58:24: adding an appropriate PATH variable for use with MacPorts.
Try adding
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
I don't see any path for python 3.5, however.
Honestly I would scratch all this and install python, pip and virtualenv using homebrew so everything is in /usr/local/bin/
I'm trying to create a virtualenv with virtualenvwrapper, but when I use mkvirtualenv I get the following :
ERROR: virtualenvwrapper could not find virtualenv in your path
I assumed it was a PYTHONPATH problem.
But if I do a pip show virtualenv I get the following :
---
Metadata-Version: 2.0
Name: virtualenv
Version: 13.1.0
Summary: Virtual Python Environment builder
Home-page: https://virtualenv.pypa.io/
Author: Jannis Leidel, Carl Meyer and Brian Rosner
Author-email: python-virtualenv#groups.google.com
License: MIT
Location: /Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages
Requires:
And here is my PYTHONPATH :
/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/bin:/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/bin:/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages:/Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages:~/.brew/Cellar
It contains the directory containing virtualenv!
(i-e : /Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages )
My ~/.zshrc contains :
export WORKON_HOME=~/Envs
export PROJECT_HOME=$HOME/Devel
source $HOME"/Library/Python/2.7/bin/virtualenvwrapper.sh"
EDIT :
virtualenvwrapper.sh is written in bash, perhaps should I check my PATH instead of my PYTHONPATH ?
So, what could the problem be? How could I fix it?
Thank you in advance for your help.
Re-installling virtualenv fixed my problem.
I had the same issue.
$ mkvirtualenv mysite
ERROR: virtualenvwrapper could not find virtualenv in your path
After a lot of time consuming efforts,
I decided to re-install virtualenv.
sudo apt install virtualenv
This fixed my issues.
I already had virtualenv installed. But I think it got broken or met with some errors.
I am using python3 with virtualenvwrapper installed on Ubuntu 18.04, using pip3 without sudo. If you are in this situation, you might find interesting my configuration.
In the end of my .bashrc I added the following rows (remember to put your username in the YOUR_USERNAME field):
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV=/home/YOUR_USERNAME/.local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
Then restart the cli with ctrl-D ctrl-T or reload the config with source ~/.bashrc.
Then you should be good to go! Try the installation with:
lsvirtualenv
mkvirtualenv test
workon test
deactivate
rmvirtualenv test
If you could create and delete a virtual environment, you are ready to go.
sudo find / -name "virtualenv"
Then I find the executable file path is:
/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/bin/virtualenv
Touch a soft link in the /usr/local/bin/ directory or add the path to .bash_profile, I prefer the former:
sudo ln -s /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/bin/virtualenv /usr/local/bin/virtualenv
I finally found out what the problem was :
virtualenvwrapper.sh is written in BASH and not in Python.
So virtualenv is called from a shell (zsh).
I didn't have to bother about my PYTHONPATH, but about my PATH (I was already able to import virtualenv from my python shell anyway).
I just added the correct directory to my PATH and everything worked fine (the directory containing the virtualenv executable, i-e /Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages which isn't included in my PATH by default despite being the directory virtualenv and other pip-installed tools was in).
Find where is your virtualenvwrapper located. in my case
~/.local/bin
May be it's installed in
/usr/local/bin/
It totally depends on the System or Package Manager you are using.
Add this path in your shell configuration .bashrc or .zshrc or whatever by simply
PATH=$PATH:<directory_you_want_to_add>
for example
PATH=$PATH:~/.local/bin
Also add the following configuration in .bashrc or .zshrc
# the path you want your virtual environments to be saved and loaded from
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/<project_folder>
# most important, this is the program which loads virtualenv
# please update the path where virtualenvwrapper.sh is located
source /usr/local/bin/virtualenvwrapper.sh
Don't Forget to restart the shell.. or reload the configuration...
To test whether it worked
mkvirtualenv test
if you see a test environment created then everything is ok.
For Detailed Installation Instructions go to the docs: virtualenvwrapper installation
For me it was:
export PYTHONPATH=/usr/bin/python3
export PATH=$HOME/.local/bin:$PATH
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source ~/.local/bin/virtualenvwrapper.sh
I changed the line to:
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv
It worked.
ERROR: virtualenvwrapper could not find virtualenv in your path
This error means - program virtualenv is not in your system path. This mostly happens if you install virtualenv via pip without sudo. This kind of installation stores data in users local directory e.g ~/.local/bin. So first step is to find where this binary present. You can do that using locate program. First update its database using sudo updatedb. Then run locate *bin/virtualenv. Whatever path you get, append it in system path variable. This you can do by adding below line in your shell config file e.g. ~/.bashrc or ~/.zshenv.
export PATH=$PATH:/your/path
e.g.
export PATH=$PATH:~/.local/bin
Now open new shell and try again. Error should be gone.
In my case, I tested use this command:
sudo find / -name "virtualenv"
and I have a list with all path to this file,
I tested one to one and solved with path:
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv
My configurations to environment variables is :
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenv
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv
source ~/.local/bin/virtualenvwrapper.sh
in file .bashrc.
Now all its works.
The way I did it was (using zsh) in this way:
export PATH=$HOME/bin:/usr/local/bin:$PATH:/Users/username/Library/Python/2.7/bin:$PATH
I simply located the file of virtualenvwrapper.sh inside this path /Users/username/Library/Python/2.7/bin:$PATH
and added that path to PATH.
I have set the variable VIRTUALENVWRAPPER_VIRTUALENV in my .zshrc to the full path of the virtualenv binary and it works for me.
Here is my .zshrc file:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_VIRTUALENV=$HOME/Library/Python/2.7/bin/virtualenv
source $HOME/Library/Python/2.7/bin/virtualenvwrapper.sh
Your PYTHONPATH makes me think you have Homebrew installed. It sounds like virtualenvwrapper was installed with either your system pip or your homebrew pip while it is being executed with the opposite python interpreter.
I had this same issues and tried many many things, what found as a solution is i had three pip version, pip with 2.7, 3.6 and 3.7. and 3.6 was the one works fine for many things, and install as sudo pip3.6 install virtualenv, and it works fine.
I would suggest, check your pip version and tried to install based on your pip ver.
Removing all virtualenv related packages would work.
pip freeze -l | grep ^virtualenv | awk -F= '{print $1}' | xargs pip uninstall -y
Given what I know about Python, the problem I'm having shouldn't been happening. I installed virtualenvwrapper on Mac OS X Snow Leopard with pip. It's there in /Library/Python/2.6/site-packages. But when I try to import virtualenvwrapper, Python tells me there's no such module with that name. Other modules (e.g. virtualenv) load just fine, and /Library/Python/2.6/site-packages is right at the top of my Python path. So is there something weird about virtualenvwrapper so that Python isn't finding it?
Mine is in /usr/local/bin/virtualwrapper.sh but you should be able to add this to your .bashrc, .bash_profile, or .profile to put into your environment. (Remember to do source .bashrc or open a new terminal window)
source /Library/Python/2.6/site-packages/virtualenvwrapper.sh
EDIT Here's my entire bash profile related to pip, virtualenv and virtualenv wrapper since it looks ugly as a comment
# python
export PATH=/usr/local/share/python:$PATH
export PYTHONPATH=/usr/bin/python:$PYTHONPATH
export PATH=/usr/local/MacPorts/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH
export VIRTUALENVWRAPPER_PYTHON=/usr/local/MacPorts/Library/Frameworks/Python.framework/Versions/2.7/bin/python
#virtualenv wrapper
export WORKON_HOME=~/.virtualenvs
# mkvirtualenv --no-site-packages myenv
source /usr/local/MacPorts/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=$WORKON_HOME
export PIP_RESPECT_VIRTUALENV=true
Try installing virtualenvwrapper with **sudo** pip virtualenvwrapper. It might be referring to the shell script it installs in /usr/local/bin.
I am on Mac OS X 10.9.2 with XCode 5.1.1 and for me virtualenvwrapper.sh file was present in
/usr/local/bin/virtualenvwrapper.sh
So I simply copied this into ~/.profile file:
source /usr/local/bin/virtualenvwrapper.sh
And now my ~/.profile file looks something like this:
# MacPorts Installer addition on 2014-02-23_at_17:28:39: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
source /usr/local/bin/virtualenvwrapper.sh
And now I am able to use virtualenvwrapper commands without any issue whatsoever
Hope this helps!
This worked for me:
source ~/.bashrc