Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installed Virtualenv and activating virtualenv doesn't work

I cloned my Django Project from Github Account and activated the virtualenv using famous command source nameofenv/bin/activate And when I run python manage.py runserver

It gives me an error saying:

ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?

like image 377
abhi_bond Avatar asked Oct 08 '16 16:10

abhi_bond


People also ask

Why virtualenv is not recognized?

Answers related to “virtualenv : The term 'virtualenv' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.”

How do I know if virtualenv is activated?

Check the $VIRTUAL_ENV environment variable. The $VIRTUAL_ENV environment variable contains the virtual environment's directory when in an active virtual environment. Once you run deactivate / leave the virtual environment, the $VIRTUAL_ENV variable will be cleared/empty.


1 Answers

I was thinking that every and each dependency I need, might be present inside virtualenv.

Well, no. By default, a newly created virtualenv comes empty, that is, with no third-party library. (Optionaly, you may allow a virtualenv to access libraries installed system-wide, but that's another story.)

Once the virtualenv is created, you need to install the dependencies you need.

(How could virtualenv know what dependencies you need?)

The procedure is to install the virtualenv, activate it, and then install the libraries needed for the project (in you case Django and perhaps others).

If you project has a requirements.txt, you may install every required dependency with the command:

pip install -r requirements.txt

If your project has a setup.py, you may also execute

pip install -e path/to/your/project/clone/.

to install the project in the virtualenv. This should install the dependencies.

Of course, if the only dependency is Django, you can just type

pip install django
like image 81
Jérôme Avatar answered Sep 21 '22 17:09

Jérôme