如何用Python 3.5运行Django?

时间:2021-12-07 19:18:00

After source ./bin/activate, on doing a which python3.5 I get the following response

在源./bin/activate之后,在做一个python3.5时,我得到以下响应

/path/to/virtualenv/bin/python3.5

I am using Django 1.10.5 which according to their documentation supports Python 3.5. But on doing python3.5 manage.py runserver, I get the following error,

我正在使用Django 1.10.5,根据他们的文档支持Python 3.5。但是在做python3.5 manage.py runserver时,我收到以下错误,

Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ImportError: No module named 'django'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    import django
ImportError: No module named 'django'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 17, in <module>
    "Couldn't import Django. Are you sure it's installed and "
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?

My project works perfectly fine with the default python 3 (3.4) in my Ubuntu 14.04 system. What is the issue here?

我的项目在我的Ubuntu 14.04系统中使用默认的python 3(3.4)完全正常。这是什么问题?

If it's any help, I followed this process to install python 3.5. I did not remove the existing python3 from the machine as given in the end of the answer. I have both python3 and python3.5

如果有任何帮助,我按照这个过程安装python 3.5。我没有从答案末尾给出的机器中删除现有的python3。我有python3和python3.5

2 个解决方案

#1


0  

It seems like you have not installed django in the virtual environment. You need to install all the dependencies in your virtual environment. try using pip:

好像你还没有在虚拟环境中安装django。您需要在虚拟环境中安装所有依赖项。尝试使用pip:

pip install Django

you can find more details here https://docs.djangoproject.com/en/1.10/topics/install/.

你可以在这里找到更多细节https://docs.djangoproject.com/en/1.10/topics/install/。

#2


0  

After some digging, it seems we are not able to add a new Python version into an existing virtualenv. So, I created a new virtual environment using the command

经过一番挖掘,似乎我们无法在现有的virtualenv中添加新的Python版本。因此,我使用该命令创建了一个新的虚拟环境

virtualenv -p python3.5 project-name

virtualenv -p python3.5项目名称

Here -p specifies which python you want in the environment. Although the default python and python3 are also included, which is a good thing. I then copied my existing django project there, and installed all the dependencies with pip3 install -r requirements.txt. I used pip3 because I am using python3.5.

这里-p指定你想要在环境中使用哪个python。虽然默认的python和python3也包含在内,这是一件好事。然后我复制了我现有的django项目,并使用pip3 install -r requirements.txt安装了所有依赖项。我使用pip3因为我使用的是python3.5。

After this, doing a python3.5 manage.py runserver worked like it's supposed to. Hope this helps someone.

在此之后,做一个python3.5 manage.py runserver就像它应该的那样工作。希望这有助于某人。

#1


0  

It seems like you have not installed django in the virtual environment. You need to install all the dependencies in your virtual environment. try using pip:

好像你还没有在虚拟环境中安装django。您需要在虚拟环境中安装所有依赖项。尝试使用pip:

pip install Django

you can find more details here https://docs.djangoproject.com/en/1.10/topics/install/.

你可以在这里找到更多细节https://docs.djangoproject.com/en/1.10/topics/install/。

#2


0  

After some digging, it seems we are not able to add a new Python version into an existing virtualenv. So, I created a new virtual environment using the command

经过一番挖掘,似乎我们无法在现有的virtualenv中添加新的Python版本。因此,我使用该命令创建了一个新的虚拟环境

virtualenv -p python3.5 project-name

virtualenv -p python3.5项目名称

Here -p specifies which python you want in the environment. Although the default python and python3 are also included, which is a good thing. I then copied my existing django project there, and installed all the dependencies with pip3 install -r requirements.txt. I used pip3 because I am using python3.5.

这里-p指定你想要在环境中使用哪个python。虽然默认的python和python3也包含在内,这是一件好事。然后我复制了我现有的django项目,并使用pip3 install -r requirements.txt安装了所有依赖项。我使用pip3因为我使用的是python3.5。

After this, doing a python3.5 manage.py runserver worked like it's supposed to. Hope this helps someone.

在此之后,做一个python3.5 manage.py runserver就像它应该的那样工作。希望这有助于某人。