1

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

  1. just copying the Anaconda virtualenvwrapper.sh file as suggested?
  2. 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
  • @klanomath I understand what you are saying, but before I do it - do you currently have Anaconda? If so do both Django and Anaconda work in harmony? – rishijd May 3 '18 at 22:36
  • 1
    I have some VMs with Anaconda installed but I don't develop apps actively with it. If you want to learn more than Django (i.e. use other Anaconda packages) Anaconda is probably OK. – klanomath May 3 '18 at 22:52
  • 1
    if your using python installed with Anacoda, you may want to install virtual environments following the directions in the Anaconda docs. Very easy and straight forward. – jmh May 3 '18 at 23:02
  • 1
    an equally good method is to google "anaconda virtual environment" – jmh May 3 '18 at 23:05
  • 1
    To use MAMP/MAMP Pro's mysql you have to add proper paths to its binaries (i.e. /Applications/MAMP/Library/bin). Additionally you'd have to install some connectors – klanomath May 3 '18 at 23:06
1

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

 which python  

You should get

/Users/mark/anaconda3/bin/python

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

  • Thanks a lot! I actually installed it using pip as mentioned here: felipegalvao.com.br/blog/2017/01/03/… and it all works fine now. From the comments above with the others, I also realized changed my mind from treating Anaconda as a 'side' installation of Python, to treating it as my 'main' python. The environment I'm using (see link) is from conda which works great too. – rishijd May 5 '18 at 23:54
  • 1
    The problem with random blogs on the web unless they are part of a curated series they are not necessarily the best practice. As noted in the comments conda not pip is the best way and the blog author admits he does not know whey he had to use pip. StackExchnage etc is better as answers are voted on or edited. Don't use a single blog unless you can crossreference it to another saying the same thing or else it is a trusted site. – Mark May 6 '18 at 10:13
  • that's a great point, thank you, I didn't realize it. In my situation, what would you do? Perhaps I can delete my virtual environment with pip/django, and then create a new virtual enviroment with conda to be safe? I also want to install anaconda.org/anaconda/coverage into my environment, but I'm wary to use conda on my current environment where django was installed with pip (within Anaconda) – rishijd May 6 '18 at 12:39
  • If you want anaconda as your main python I would put it on the path before and use conda for environment and start from scratch. (You don't have to but if you want to manage both you need to have a better unbderstanding of how they interact) conda will create new environments – Mark May 6 '18 at 17:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .