简体   繁体   中英

Python virtualenv no module named django

In my ec2 machine i need to run a django project, I do the below thinks:

Install python 3.4:

sudo yum install python34

ok, now i create a virtual enviroment for python 3:

virtualenv -p python3 .venv3

at this point activate my venv:

source .venv3/bin/activate

all done! Now i have to install django:

pip install django

the installation was ok but when i try to check my django version:

python -c "import django; print(django.get_version())"

system return the error "No module name django found" How is possible? In my machine there is also python 2.7 installed. I try outside the virtualenv to remove django with:

sudo python -m pip uninstall django

all done, but in my .venv3 enviroment the issue is still present. How can i fix the problem?

i also tried to reinstall django like this:

 pip install --upgrade --force-reinstall django

response:

Collecting django Using cached https://files.pythonhosted.org/packages/56/0e/afdacb47503b805f3ed213fe732bff05254c8befaa034bbada580be8a0ac/Django-2.0.6-py3-none-any.whl Collecting pytz (from django) Using cached https://files.pythonhosted.org/packages/dc/83/15f7833b70d3e067ca91467ca245bae0f6fe56ddc7451aa0dc5606b120f2/pytz-2018.4-py2.py3-none-any.whl Installing collected packages: pytz, django Found existing installation: pytz 2018.4 Uninstalling pytz-2018.4: Successfully uninstalled pytz-2018.4 Successfully installed django-2.0.6 pytz-2018.4

but when i try:

pip freeze

response is:

gunicorn==19.8.1 pytz==2018.4 virtualenv==16.0.0

Why django isn't installed?

thanks in advance

The answer to your question depends on your version of python so you need to install pip3

sudo apt-get install python3-pip

Then, you have to create a virtual environment with venv

pip3 -p python3.6 virtualenv name

After that install Django:

pip3 install Django

As in the recent version, you can use

apt-get install python3-django

Or you can simply do the follwing:

sudo apt-get install python3 virtualenvwrapper

mkvirtualenv <venv> -p python3

workon <venv>

--system-site-packages

pip install Django

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM