[英]Python virtualenv no module named django
In my ec2 machine i need to run a django project, I do the below thinks: 在我的ec2机器上,我需要运行django项目,我认为以下几点:
Install python 3.4: 安装python 3.4:
sudo yum install python34
ok, now i create a virtual enviroment for python 3: 好的,现在我为python 3创建一个虚拟环境:
virtualenv -p python3 .venv3
at this point activate my venv: 此时激活我的venv:
source .venv3/bin/activate
all done! 全部做完! Now i have to install django:
现在我必须安装django:
pip install django
the installation was ok but when i try to check my django version: 安装还可以,但是当我尝试检查Django版本时:
python -c "import django; print(django.get_version())"
system return the error "No module name django found" How is possible? 系统返回错误“找不到模块名称django”,怎么可能? In my machine there is also python 2.7 installed.
在我的机器上还安装了python 2.7。 I try outside the virtualenv to remove django with:
我尝试在virtualenv外部使用以下方法删除Django:
sudo python -m pip uninstall django
all done, but in my .venv3 enviroment the issue is still present. 全部完成,但是在我的.venv3环境中,此问题仍然存在。 How can i fix the problem?
我该如何解决该问题?
i also tried to reinstall django like this: 我也试图像这样重新安装django:
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
使用缓存的https://files.pythonhosted.org/packages/56/0e/afdacb47503b805f3ed213fe732bff05254c8befaa034bbada580be8a0ac/Django-2.0.6-py3-none-any.whl使用缓存的https:// files收集pytz(来自django)。 .org / packages / dc / 83 / 15f7833b70d3e067ca91467ca245bae0f6fe56ddc7451aa0dc5606b120f2 / pytz-2018.4-py2.py3-none-any.whl安装收集的软件包:pytz,django找到现有安装:pytz 2018.4成功卸载pytz-2018.4:成功安装pytz-2018.4: -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
gunicorn == 19.8.1 pytz == 2018.4 virtualenv == 16.0.0
Why django isn't installed? 为什么没有安装django?
thanks in advance 提前致谢
The answer to your question depends on your version of python so you need to install pip3 您问题的答案取决于您的python版本,因此您需要安装pip3
sudo apt-get install python3-pip
Then, you have to create a virtual environment with venv 然后,您必须使用venv创建虚拟环境
pip3 -p python3.6 virtualenv name
After that install Django: 之后安装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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.