I installed virtualenv using the command sudo pip install virtualenv and the installation is successful. Later, when I type virtualenv, I get the error message as following, -bash: virtualenv: command not found
The virtualenv is installed in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages. I see the similar questions in the forum with no definitive answers.
Python is in the location /usr/local/bin/python and I have version 2.7.9. I get the following using ls -l command,
Why do I see the virtualenv is not found and how to solve the issue ?
UPDATE:
I use the command
ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py /usr/local/bin/virtualenv.py to put the virtualenv.py
inside the /usr/local/bin folder. Previously, I only did the same for the virtualenv file. Now, when I put the command virtualenv in the terminal, I get
-bash: /usr/local/bin/virtualenv: Permission denied.
I later use
sudo ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py /usr/local/bin/virtualenv.py
and the say message keep showing. which virtualenv still returns nothing.
Pursuant to #Jason's suggestion, try making the symbolic link for virtualenv in the /bin directory like so:
ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv /usr/local/bin/virtualenv
Why don't re-install virtualenv? Also try to use the latest version of pip (sudo pip install -U pip).
Not sure if the answer will be useful to you, as i see the question is a few month old, but maybe it will be helpful for others.
I encountered the same problem, after installing python3.5 and pyCharm on my Mac. I moved the 3.5 folder from /Library/Frameworks/Python.framework/Versions/3.5 to /System/Library/Frameworks/Python.framework/Versions/3.5, following this guide, after disabling the System Integrity Protection first with reboot into recovery mode (boot with ctrl+R), and executing csrutil disable in the terminal. After reboot it was possible to move the python3.5 folder, and then i followed the guide, and everything worked like charm. In pyCharm i could choose the version 3.5 from /System/... instead of /Library/... (however, i still left a soft link in /Library/... to the /System folder where the python3.5 now was, just in case), and after adding the path to my zsh i could execute pip3 install virtualenv. So far so good.
Next, i tried to create the environment with virtualenv -p python3 env, and here i had the same problem as you. It seemed like the path could not be added somehow. Initially i also tried to look in the /System/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/ and include it in the $PATH, then also create softlinks to virtualenv.py as you tried too, but finally found that although all the files are in the site-packages folder, the actual executable was in /System/Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenv. As the path there was included in my $PATH, i have no idea why it did not execute when typing virtualenv -p python3 env, even with sudo as you tried too, but once i typed the full path /System/Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenv -p python3 env, it worked like charm again.
I still have no idea why, but it worked and now i can move on :)
Hope it helps, and hope someone can explain this better than me.
You are created the symbolic link to the wrong file. As far as I know virtualenv is installed to /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv, (you can change the numbers for your Python version) so the command for creating the symbolic link should be:
ln -s /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv /usr/local/bin/virtualenv
Related
I have installed python2 and python3 in my Mac osx and currently I'm using python3. And I am able to pip3 install virtualenv and virtualenvwrapper. The problem is whenever I restart my terminal, the settings for virtualenvwrapper don't work, like I can't use the commands mkvirtualenv and workon. The error I get is bash: the command workon is not found. I think there must be something wrong with my settings about the virtualenvwrapper. Here is what I try:
edit the ~/.bashrc:
export WORKON_HOME=~/Envs
source ~/Envs/django_projects/bin/virtualenvwrapper.sh
All my virtualenv packages are installed in the ~/Envs and after that, I source the .bashrc and it works, I could use workon and mkvirtualenv but once I reopen a new terminal it still could find't the workon command.
Does anyone know what's wrong with my setting?
After a few try, finally it works. There are two problems. The first one is because I have both python2 and python3 installed in my machine and by default the virtualenvwrapper try to run using the default python(in /usr/bin/python which is python2) so I have to change it to point to python3. So in my .bashrc file:
export WORKON_HOME=~/Envs
export VIRTUALENVWRAPPER_PYTHON=PATHS/TO/PYTHON3
source ~/Envs/django_projects/bin/virtualenvwrapper.sh
The second one is that .bashrc doesn't run automatically,we have to source in to ./bash_profile. Check https://apple.stackexchange.com/questions/12993/why-doesnt-bashrc-run-automatically for detail.
Then reopen the terminal and ta-da.
In order to be able to use virtualenvwrapper you need to source the script that is somewhere in /Users/mic4ael/Library/Python/{Python version}/bin/virtualenvwrapper.sh. So you could put source /Users/mic4ael/Library/Python/{Python version}/bin/virtualenvwrapper.sh to your .bashrc to make it every time you launch a terminal.
I was hoping someone might be able to provide a resource that will help me install python 3.6.0 on a shared hosting account at Bluehost. I’ve tried using the documentation for python 2.7 but have been unsuccessful to date. The current state of the machine now is if I run python –V it says 2.6.6 . If, however I place:
export PATH=$HOME/python/Python-3.6.0/:$PATH
in the .bashrc file in my home directory and then run python –V it says 3.6.0 However I am unable to get pip to work. I also noticed that during the python setup procedure permission was denied on a number of files.
I am really at a lost as there seems to be very little documentation for how to do this on a shared hosting environment. Your help would be greatly appreciated.
here's a link to the instructions I followed python
I thought pip would be installed as it said pip 9.0.2 was installed but when I try to run it it say cxommand not found. When I tried easy_install pip I got back the following error message:
[Errno 30] Read-only file system: '/usr/lib/python2.6/site-packages/test-easy-install-13141.write-test'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/usr/lib/python2.6/site-packages/
You cannot install the package because it is trying to install them in the system directory, and you do not have write access.
If you can, use a virtualenv. Of course this requires virtualenv be installed.
Put the virtualenv somewhere you have write access to. For example, use these instructions.
Enter the following commands to download and extract Python
3.6 to your hosting account.
mkdir ~/python
cd ~/python
wget http://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
tar zxfv Python-3.6.0.tgz
find ~/python -type d | xargs chmod 0755
cd Python-3.6.0
Install Python
Once extracted you can use the following commands to
configure and install Python.
./configure --prefix=$HOME/python
make
make install
Modify the .bashrc
For your local version of python to load you will need to add
it to the .bashrc file.
vim ~/.bashrc
Press i
Enter:
export PATH=$HOME/python/Python-3.6.0/:$PATH
export PYTHONPATH=$PYTHONPATH:$HOME/python/python3.6/site-packages/
Write the changes (press ESC) and close vim:
:wq
Press Enter
source ~/.bashrc
Now to use pip:
python -m pip install package-of-interest
You could also ask the system administrator to install the package for you. This might be the only real option if virtualenv hasn't been installed. Ask the administrator to install virtualenv.
In attempting to get started learning and developing python, I've tried to follow the Python Guide to installing python on OS X, but haven't found it particularly "noob friendly." I have a new MacBook (Mtn. Lion - OS X 10.8.3) wich comes with Python 2.7.2 built in. But the guide advises installing a "framework-style build" via homebrew. So:
I installed homebrew via ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
Then it tells you to add homebrew to the top of your PATH by adding it to your ~/.bashrc file. ls -a showed that I did not have a ~/.bashrc file in my home directory. After searching Stack Overflow on how to do that, I ran nano ~/.bashrc, and inserted the line export PATH=/usr/local/bin:$PATH to the file and saved the file.
I then ran brew install python --framework and the install completed.
Then, the guide says to "add the new Python scripts directory to your PATH" so, I'm assuming that means I need to add the line it provides to my ~/.bashrc file also. So, I added export PATH=/usr/local/share/python:$PATH to my ~/.bashrc file above my previous entry.
Finally, this is where I run into trouble, it says to easy_install pip. However, when I do that I get an error 13.
So, here are the things I need some help with.
Was I correct in my assumptions about how to add homebrew and python scripts to my PATH?
Did I do something wrong or do I just need to use sudo to install pip? (I'm really sorry if the answer is already on this page but even those answers don't make total sense to me and I want to be careful and not screw something up)
After installing the framework-style build of python (which I believe was the current 2.7.3), how come running python in my terminal still shows v2.7.2?
Thanks! I appreciate any help.
I've tried to follow the Python Guide to installing python on OS X,
but haven't found it particularly "noob friendly.
Yes, I think it is misleading/outdated.
Then it tells you to add homebrew to the top of your PATH by adding it
to your ~/.bashrc file. ls -a showed that I did not have a ~/.bashrc
file in my home directory. After searching Stack Overflow on how to do
that, I ran nano ~/.bashrc, and inserted the line export
PATH=/usr/local/bin:$PATH to the file and saved the file.
On the Mac, just use ~/.profile
I then ran brew install python --framework and the install completed.
I think you don't need the --framework option unless you want to replace your Mac OS default installation and need an Mac OS Framework-style directory layout. There is no need to replace it though, the homebrew installation will take precedence anyway.
Then, the guide says to "add the new Python scripts directory to your
PATH" so, I'm assuming that means I need to add the line it provides
to my ~/.bashrc file also. So, I added export
PATH=/usr/local/share/python:$PATH to my ~/.bashrc file above my
previous entry.
Again, do it in ~/.profile. And don't forget to do a
source ~/.profile
otherwise the changes will only become active in any new terminal window, not the one you are currently using.
Finally, this is where I run into trouble, it says to easy_install
pip. However, when I do that I get an error 13.
The error shows that you try to install it your Mac OS system's default Python library (rather than in /usr/local, homebrew style), which would require root privileges. Just don't.
Also, with homebrew python, pip is already installed.
Check your path:
$ which pip
/usr/local/bin/pip
$ ls -l /usr/local/bin/pip
[..] /usr/local/bin/pip -> ../Cellar/python/2.7.3/bin/pip
Added bonus: Then do
pip install virtualenv
and use that.
And to your questions:
Was I correct in my assumptions about how to add homebrew and python
scripts to my PATH?
Yes, but use .profile and do a source .profile afterwards.
Did I do something wrong or do I just need to use sudo to install pip?
(I'm really sorry if the answer is already on this page but even those
answers don't make total sense to me and I want to be careful and not
screw something up)
You don't need sudo with homebrew, and pip is installed automatically with homebrew python.
After installing the framework-style build of python (which I believe
was the current 2.7.3), how come running python in my terminal still
shows v2.7.2?
Probably PATH not correct, do echo $PATH and check that it is correct. That is unrelated to being "framework-style" or not, though.
If you installed python with homebrew, you should already have pip installed. Try running
pip --version
to see whether and where pip is installed. Hopefully it's in a /usr/local/... path where your other homebrew things live.
Also before you install too much more with homebrew be sure to run these commands:
brew update
brew doctor
Good luck!
I am trying to find out why my virtualenv and/or virtualenv wrapper - installed using pip using homebrew - cannot be found. I think it's because it's not added to my PATH:
$ which virtualenv
$
and:
$ virtualenv someDir
$ -bash: virtualenv: command not found
I installed pip using homebrew, and virtualenv using pip, without problems. I tried reinstalling virtualenv, but that did not work either.
How do I know what path to add to PATH? Just the path that virtualenv.py seems to be installed into? That seems to be:
/usr/local/lib/python2.7/site-packages/virtualenv.py
I also found this guide, which suggests this:
$ ln -s ../Cellar/python/2.7/Frameworks/Python.framework/Versions/2.7/bin/virtualenv virtualenv
However, it does not help me run virtualenv. I am on Mac OSX 10.7.5 (Lion).
It seems that I myself am the exception to the rule for almost all 'simple' installation procedures. For some reason, it WAS a path related issue:
I ran brew info python, which outputted a lot of information. At the bottom I found this:
Executable python scripts will be put in:
/usr/local/share/python
so you may want to put "/usr/local/share/python" in your PATH, too.
I added that to my PATH in /etc/launchd.conf and ~/.bashrc and lo and behold:
$ which virtualenv
tells me:
"/usr/local/share/python/virtualenv"
I still don't know why I couldn't find any pointers in the right direction, online, anywhere? Is pip install virtualenv supposed to add to the PATH itself? If so, why not on my system? Why did #bibhas tell me explicitly it was not a path issue?
Had the same issue after pip install virtualenv
When I inspected python ls -la /usr/local/bin/python I found it was symbolically linked to /Library/Frameworks/Python.framework/Versions/2.7/bin/python
When I cd in that directory I also found the virtualenv executable and
Fixed it by
cd /Library/Frameworks/Python.framework/Versions/2.7/bin
ln virtualenv /usr/local/bin/virtualenv
Sidenote: I also happen to have a python installation in /System/Library/Frameworks/Python.framework/Versions/2.7/bin
I believe that's the one that came with OSX
In your .bashrc you need to have:
export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
(Mac / Linux specific)
So I got an error message when I did a pip3 install --user --upgrade virtualenv telling me that I did not have Users/home/Library/Python/3.7/bin in my PATH. So I simply added it.
If this is on the Mac, the following did it for me
vi ~/.bash_profile
PATH="/Users/home/Library/Python/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
restart your terminal and type virtualenv env and that should do it.
I solved it by:
At first, I found out it is located at /usr/local/python3
and then I fixed it by the command:
ln virtualenv /usr/local/bin/virtualenv
This solution will give you an alternate tool to use and solve your virtualenv problem at the same time.
Use pythonbrew. It is inspired from rvm in the ruby world and is helpful in managing pythons on your system and also wrap virtualenv commands to provide virtual environment management. I use it Mountain Lion for my development purposes and have had no problems. More details (on my blog): http://stacktoheap.com/blog/2013/03/11/why-use-virtualenv-when-there-is-pythonbrew/
My idea is to add your virtualenv position to the BASH PATH
export PATH=$PATH:/usr/local/python2.7/bin
Or change your position
For those with Python 2.7, I came across this as well, and solved it by simply putting the following line into the \etc\paths file (may need to $ sudo chmod it first):
/Library/Frameworks/Python.framework/Versions/2.7/bin
Save the change and start a new Terminal session. Check it with echo $PATH
The module in /usr/local/lib/python2.7/site-packages is imported by a short script that uses pkg_resources.load_entry_point to run the application. The utility script should be in /usr/local/bin.
I've installed virtualenv via pip and get this error after creating a new environment:
selenium:~ auser$ virtualenv new
New python executable in new/bin/python
ERROR: The executable new/bin/python is not functioning
ERROR: It thinks sys.prefix is u'/System/Library/Frameworks/Python.framework/ Versions/2.6' (should be '/Users/user/new')
ERROR: virtualenv is not compatible with this system or executable
In my environment:
PYTHONPATH=/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
PATH=/System/Library/Frameworks/Python.framework/Versions/2.6/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
How can I repair this?
Thanks.
Just in case there's someone still seeking for the answer.
I ran into this same problem just today and realized since I already have Anaconda installed, I should not have used pip install virtualenv to install virtual environment as this would give me the error message when trying to initiate it later. Instead, I tried conda install virtualenv then entered virtualenv env_mysite and problem solved.
Like #RyanWilcox mentioned, you might be inadvertently pointing virtualenv to the wrong Python installation. Virtualenv comes with a -p flag to let you specify which interpreter to use.
In my case,
virtualenv test_env
threw the same error as yours, while
virtualenv -p python test_env
worked perfectly.
If you call virtualenv -h, the documentation for the -p flag will tell you which python it thinks it should be using; if it looks wonky, try passing -p python. For reference, I'm on virtualenv 1.11.6.
In case anyone in the future runs into this problem - this is caused by your default Python distribution being conda. Conda has it's own virtual env set up process but if you have the conda distribution of python and still wish to use virtualenv here's how:
Find the other python distribution on your machine: ls -ls /usr/bin/python*
Take note of the availble python version that is not conda and run the code below (note for python 3 and above you have to upgrade virtualenv first): virtualenv -p python2.7(or your python version) flaskapp
I've run across this problem myself. I wrote down the instructions in a README, which I have pasted below....
I have found there are two things that work:
Make sure you're running the latest virtualenv (1.5.1, of this writting)
If you're using a non system Python as your standard Python (which python to check) Forcefully use the System supplied one.
Instead of virtualenv thing use /usr/bin/python2.6 PATH/TO/VIRTUALENV thing (or whatever which
python returned to you - this is what it did for me when I ran into this issue)
I had the same problem and as I see it now, it was caused by a messy Python installation. I have OS X installed for over a year since I bought a new laptop and I have already installed and reinstalled Python for several times using different sources (official binaries, homebrew, official binaries + hand-made adjustments as described here). Don't ask me why I did that, I'm just a miserable newbie believing everything will fix itself after being re-installed.
So, I had a number of different Pythons installed here and there as well as many hardlinks pointing at them inconsistently. Eventually I got sick of all of them and reinstalled OS X carefully cleaned the system from all the Pythons I found using find utility. Also, I have unlinked all the links pointing to whatever Python from everywhere. Then I've installed a fresh Python using homebrew, installed virtualenv and everything works as a charm now.
So, my recipe is:
sudo find / -iname "python*" > python.log
Then analyze this file, remove and unlink everything related to the version of Python you need, reinstall it (I did it with homebrew, maybe official installation will also work) and enjoy. Make sure you unlink everything python-related from /usr/bin and /usr/local/bin as well as remove all the instances of Frameworks/Python.framework/Versions/<Your.Version> in /Library and /System/Library.
It may be a dirty hack, but it worked for me. I prefer not to keep any system-wide Python libraries except pip and virtualenv and create virtual environments for all of my projects, so I do not care about removing the important libraries. If you don't want to remove everything, still try to understand whether your Pythons are, what links point to them and from where. Then think what may cause the problem and fix it.
I ran into a variation of this "not functioning" error.
I was trying to create an environment in a folder that included the path ".../Programming/Developing..." which is actually "/Users/eric/Documents/Programming:Developing/"
and got this error:
ImportError: No module named site
ERROR: The executable env/bin/python2.7 is not functioning
ERROR: It thinks sys.prefix is u'/Users/eric/Documents/Programming:Developing/heroku' (should be u'/Users/eric/Documents/Programming:Developing/heroku/env')
ERROR: virtualenv is not compatible with this system or executable
I tried the same in a different folder and it worked fine, no errors and env/bin has what I expect (activate, etc.).
I got the same problem and I found that it happens when you do not specify the python executable name properly. So for python 2x, for example:
virtualenv --system-site-packages -p python mysite
But for python 3.6 you need to specify the executable name like python3.6
virtualenv --system-site-packages -p python3.6 mysite
On on OSX 10.6.8 leopard, after having "upgraded" to Lion, then downgrading again (ouch - AVOID!), I went through the Wolf Paulus method a few months ago, completely ignorant of python. Deleted python 2.7 altogether and "replaced" it with 3.something. My FTP program stopped working (Fetch) and who knows what else relies on Python 2.7. So at that point I downloaded the latest version of 2.7 from python.org and it's installer got me up and running - until i tried to use virtualenv.
What seems to have worked for me this time was totally deleting Python 2.7 with this code:
sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7
removing all the links with this code:
sudo rm /usr/bin/pydoc
sudo rm /usr/bin/python
sudo rm /usr/bin/pythonw
sudo rm /usr/bin/python-config
I had tried to install python with homebrew, but apparently it will not work unless all of XTools is installed, which I have been avoiding, since the version of XTools compatible with 10.6 is ancient and 4GB and mostly all I need is GCC, the compiler, which you can get here.
So I just installed with the latest download from python.org.
Then had to reinstall easy_install, pip, virtualenv.
Definitely wondering when it will be time for a new laptop, but there's a lot to be said for buying fewer pieces of hardware (slave labor, unethical mining, etc).
The above solutions failed for me, but the following worked:
python3 -m venv --without-pip <ENVIRONMENT_NAME>
. <ENVIRONMENT_NAME>/bin/activate
curl https://bootstrap.pypa.io/get-pip.py | python
deactivate
It's hacky, but yes, the core problem really did just seem to be pip.
I did the following steps to get virtualenv working :
Update virtualenv as follows :
==> sudo pip install --upgrade virtualenv
Initialize python3 virtualenv :
==> virtualenv -p python3 venv
I had this same issue, and I can confirm that the problem was with an outdated virtualenv.py file.
It was not necessary to do a whole install --upgrade.
Replacing the virtualenv.py file with the most recent version sufficed.
I also had this problem, and I tried the following method which worked for me:
conda install virtualenv
virtualenv --system-site-packages /anaconda/envs/tensorflow (here envs keeps all the virtual environments made by user)
source /anaconda/envs/tensorflow/bin/activate
Hope it's helpful.
I had this same issue when trying to install py2.7 on a newer system. The root issue was that virtualenv was part of py3.7 and thus was not compatible:
$ virtualenv -p python2.7 env
Running virtualenv with interpreter /usr/local/bin/python2.7
New python executable in /Users/blah/env/bin/python
ERROR: The executable /Users/blah/env/bin/python is not functioning
ERROR: It thinks sys.prefix is u'/Library/Frameworks/Python.framework/Versions/2.7' (should be u'/Users/blah/env')
ERROR: virtualenv is not compatible with this system or executable
$ which virtualenv
/Library/Frameworks/Python.framework/Versions/3.7/bin/virtualenv
# install proper version of virtualenv
$ pip2.7 install virtualenv
$ /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv -p python2.7 env
$ . ./env/bin/activate
(env) $
Open terminal and type /Library/Frameworks/Python.framework/Versions/
then type ls /Library/Frameworks/Python.framework/Versions/2.7/bin/
if you are using Python2(or any other else).
Edit ~/.bash_profile and add the following line:
export PATH=$PATH:/Library/Frameworks/Python.framework/Versions/2.7/bin/
cat ~/.bash_profile
In my case the content of ~/.bash_profile is as follows:
export PATH=$PATH:/Library/Frameworks/Python.framework/Versions/2.7/bin/
Now the virtualenv command should work.
If you continue to have trouble with virtualenv, you might try pythonbrew, instead. It's an alternate solution to the same problem. It works more like Ruby's rvm: It builds and creates an entire instance of Python, under $HOME/.pythonbrew, and then sets up some bash functions that allow you to switch easily between versions. Where virtualenv shadows the system version of Python, using symbolic links as part of its solution, pythonbrew builds entirely self-contained installations of Python.
I used virtualenv for years. It's a decent solution, but I've switched to pythonbrew lately. Having completely self-contained Python instances means that installing a new one takes awhile (since pythonbrew actually compiles Python from scratch), but the self-contained nature of each installation appeals to me. And disk is cheap.