0

I have installed Python3. I created a virtual environment to point to the new version and installed Django which is using python3. But when I am trying to use Django from the virtual environment, I am getting an error message:

ImportError: No module named 'django'

source activate
sudo pip install django
python -c "import django;"

Screen shot

helmbert
  • 35,797
  • 13
  • 82
  • 95
user3287367
  • 161
  • 1
  • 3
  • 9

2 Answers2

4

Don't use sudo when using virtualenv, just use pip will do the installation.

Because sudo pip install will install into your global python, not the virtualenv.

Yeo
  • 11,416
  • 6
  • 63
  • 90
  • That's true, but irrelevant; OP does not seem to have even activated their virtualenv. – Daniel Roseman May 03 '15 at 18:59
  • perhaps the image is small. anyway, I saw there's a `source activate`, so I guess he have activated the environment. and also there's a bracket `(django)` in front of the command marking the environment – Yeo May 03 '15 at 19:02
  • 1
    Yes, sorry, you're right, I couldn't read that bit. Hence why it's a bad idea to post images. – Daniel Roseman May 03 '15 at 19:09
  • I tried by only using pip without sudo but throwing a error message: PermissionError: [Errno 13] Permission denied: '/home/joker/django/lib/python3.4/site-packages/django' – user3287367 May 03 '15 at 19:17
  • @user3287367 the problem is in your virtualenv installation. How did you install your virtualenv? at least my way of installation is by using python3-pip in global environment. so to do this, you just need to type: `deactivate; sudo pip install virtualenvwrapper`. but since you already installed it using `apt-get` i believed, you need to remove it first. `apt-get remove virtualenvwrapper` and clean up those unnecessary leftover. – Yeo May 03 '15 at 19:21
  • @user3287367 https://virtualenvwrapper.readthedocs.org/en/latest/install.html#basic-installation – Yeo May 03 '15 at 19:26
1

You must install Django for your Virtualenv. After use "source activate" you must run "pip install django".

Adrian Lopez
  • 2,601
  • 5
  • 31
  • 48
  • I tried by only using pip without sudo but throwing a error message: PermissionError: [Errno 13] Permission denied: '/home/joker/django/lib/python3.4/site-packages/django' – user3287367 May 03 '15 at 19:14
  • 1
    When you are in a virtualenv always run pip instead of pip3. Virtualenv knows how to use packages from all versions. If still doesn't work, you can delete your virtualenv and try creating it again without sudo. Also try to reinstall Virtualenv, it worked once for me. – Adrian Lopez May 03 '15 at 19:18
  • Thanks ..... I have created a new virtualenv ......For new one it worked fine .....for first time I have created the environment using: virtualenv -p /usr/bin/python3.4 , second time I have used : virtualenv --python=/usr/bin/python3.4 , I don't have much idea about virtual environment creation & not sure are they making any real difference or not – user3287367 May 03 '15 at 19:32
  • The standard way to do it is "virtualenv some_name". You can see information about all parameters using "virtualenv --help" but probably you won't need them. – Adrian Lopez May 03 '15 at 19:37
  • But I need my virtualenv to point to python3 .......virtualenv some_name.... by default it points to python 2.7 – user3287367 May 03 '15 at 19:41
  • My bad, do "virtualenv -p python3 some_name". Also be aware, you need Python3 in your machine in order to use it to create a virtualenv. – Adrian Lopez May 03 '15 at 19:46
  • More documentation in case you need it: http://stackoverflow.com/questions/5844869/comprehensive-beginners-virtualenv-tutorial – Adrian Lopez May 03 '15 at 19:56