Run Django 1.9 on Python 3.5 instead of 2.7

I have Python 2.7 and 3.5 running on OSX 10.10, and also Django 1.9a - this supports both versions of Python. The problem is that I want to run Django on Python 3.5 instead of 2.7. In some threads, I found suggestions for running it by including a version of Python, for example: python3.5 manage.py runserverbut I found this error:

File "manage.py", line 8, in <module> from django.core.management import execute_from_command_line ImportError: No module named 'django'

FYI, I have no problem running Python3.5 on the same computer.

How can i solve this? many thanks!

+4
source share
5 answers

: , Django 1.9 , Django 1.8 Python 3.5. Django 1.9 , Django 1.8.6+ Python 3.5. 1.8.X 1.9.X Python 3.5. Django 1.8.X, , 1.9.X, .

Django docs Python, , Django pip.

OS X, pyvenv Python 3.

pyvenv djangodev # create the virtual env.  
source djangodev/bin/activate # activate it
pip install django

Django, 1.8.4. Django 1.9 alpha . Django, , Python 3.4 Django 1.8. . 1.9 alpha, pip

pip install django==1.9a1
+5

virtualenv . Python 2.7.12 3.5.2, Homebrew.

$ which python3
/usr/local/bin/python3

Django Python 3:

pip3 install django

Django Python 3:

python3 /usr/local/lib/python3.5/site-packages/django/bin/django-admin.py startproject mysite

:

python3 manage.py shell
python3 manage.py startapp page
python3 manage.py runserver
...

manage.py:

#!/usr/bin/env python <— instead this line (first)
#!/usr/local/bin/python3 <— must be this one

, :

./manage.py shell
./manage.py startapp page
./manage.py runserver
...
+4

Virtualenv - . , . virtualenv Python, requirements.txt , , pip.

+2

Django 3.5, Django 2.7.

pip, pip3. setup.py python3.5.

+1

Python virtualenv.

virtualenv dev_FirstDj_py35 --python=python3.5

virtualenv /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 '/Library/Frameworks/Python.framework/Versions/3.5' python /Users/raja/test _first_py35/bin/python3.5 /Users/raja/test _first_py35/bin/python setuptools, pip, wheel... done.

+1

Source: https://habr.com/ru/post/1609671/


All Articles