I'm a bit of a newbie to Python and definitely to virtual environments and Django. I want to install Django but it first recommends a virtualenv
/ virtualenvwrapper
. A video I am watching recommends installing virtualenvwrapper
so I just tried this, following these instructions:
https://virtualenvwrapper.readthedocs.io/en/latest/install.html#basic-installation
and
https://stackoverflow.com/questions/15101559/terminal-where-is-the-shell-start-up-file
I first ran
pip install virtualenvwrapper
which seemed to work fine. It generated some messages, ending with:
Downloading https://files.pythonhosted.org/packages/e1/ba/f95e3ec83f93919b1437028e989cf3fa5ff4f5cae4a1f62255f71deddb5b/pbr-4.0.2-py2.py3-none-any.whl (98kB)
100% |████████████████████████████████| 102kB 5.3MB/s
Requirement already satisfied: six>=1.10.0 in /Users/rishi/anaconda3/lib/python3.6/site-packages (from stevedore->virtualenvwrapper)
Installing collected packages: virtualenv-clone, pbr, stevedore, virtualenv, virtualenvwrapper
Successfully installed pbr-4.0.2 stevedore-1.28.0 virtualenv-15.2.0 virtualenv-clone-0.3.0 virtualenvwrapper-4.8.2
I then had to follow the "shell startup" guidelines which mentioned adding these lines to be shell startup file:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
I did this. Once I run $ source ~/.bash_profile
on terminal, I am presented with this error:
-bash: /usr/local/bin/virtualenvwrapper.sh: No such file or directory
After searching online, a forum post recommended that I run:
which virtualenvwrapper.sh
and this gives me the result:
/Users/rishi/anaconda3/bin/virtualenvwrapper.sh
Note I have Anaconda installed for some (previous) learning. I now want to install/learn Django.
Searching online, one person recommended to copy the virtualenvwrapper.sh
from the one directory to the /usr/local/bin/
directory. It also seems like I should have done this with sudo
– i.e. should I have run the following?
sudo pip install virtualenvwrapper
I'm super confused – I never was good with server/installing stuff so I'd really appreciate guidance on how/what to install correctly in order to get my virtual environment working, and then hopefully I can use Django.
Perhaps you may recommend
- just copying the Anaconda
virtualenvwrapper.sh
file as suggested? - Or if I should install again using
sudo
then please let me know how to uninstall virtualenvwrapper (that I just installed) so I can re-install it,
or please simply let me know the steps I should follow as I don't want to mess anything up, if I haven't already!
UPDATE
I copied the file from Anandonda to the main folder as explained above, and then ran this. The following messages were generated, and now I seem to be good, I can use the workon
command for example.
Rishi:bin rishi$ source ~/.bash_profile
virtualenvwrapper.user_scripts creating /Users/rishi/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /Users/rishi/.virtualenvs/postmkproject
virtualenvwrapper.user_scripts creating /Users/rishi/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /Users/rishi/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /Users/rishi/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /Users/rishi/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /Users/rishi/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /Users/rishi/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /Users/rishi/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /Users/rishi/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /Users/rishi/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /Users/rishi/.virtualenvs/get_env_details
Best Answer
You have a mix of pythons on your machine. I would stick to one.
In this case I would stick to anaconda.
SO edit your path so that anaconda is first on the path before /usr/local/bin and /usr/bin
Test by running
You should get
If a 2 rather than 3 you have python2,7 and I would switch to 3.
You can now use virtulenv etc as they are part of python 3.6 (the current 3.x version) see the python docs You should use venv now not what your tutorial shows https://docs.python.org/3/library/venv.html
However as you are using anaconda you can use conda insteaf of venv, You will find most things already installed (I use conda as it provides prebuilt C libraries when needed, pip etc can be more complex and also could require Xcode) https://conda.io/docs/user-guide/getting-started.html The django install is at https://anaconda.org/anaconda/django