How to run Django in python 3.5

1

I'm working with Django in python 2.7, for that I use virtualenv, pip, the mysql connector, etc. I have predefined python 3.5 in bash, but even so when I run ./manage.py shell it runs with python 2.7. How do I change it to python 3.5? Thank you very much!

    
asked by Genarito 22.10.2016 в 22:55
source

3 answers

1
  • Create a requirements file in your current environment:

    $ pip freeze > requisitos.txt
    
  • Then deactivate your current environment:

    $ deactivate
    
  • Then create a new virtual environment with Python 3.5, since you have predefined this interpreter:

    $ python -m venv genarito
    
  • Then activate this new environment:

    $ source genarito/bin/activate
    
  • (optional) If you consider it necessary, you can update pip

    (genarito) $ pip install --upgrade pip
    
  • Finally, you install the requirements:

    (genarito) $ pip install -r requisitos.txt
    

And that's it.

  

Verify that you use the correct connector for MySQL, I think maybe it's the only change you need: link

    
answered by 22.10.2016 / 23:14
source
1

First make sure you have the virtualenv activated. Then, that the version of python installed in that virtualenv, is version 3.x and not 2.7 or 2.x.

To check it, simply activate the virtualenv and enter in the shell:

python -V

This will give you the installed version, and if it is not correct, you can generate a new virtualenv or install the correct version.

This would be the default option.

If you want to install both versions of python, simply, when calling the command ./manage.py, do it in the following way:

'python3 ./manage.py shell'

Finally, we recommend you to install ipython, which is very useful when you work in the python or django shell.

    
answered by 22.10.2016 в 23:56
1

Python3.5 comes with a default environment system called pyvenv that works the same as virtualenv.

You just have to run in the terminal:

$ pyvenv env
$ source env/bin/activate

And from then on you can install django and the rest of the packages with pip. The default environment will run python3.5 when you execute any command like python manage.py migrate

    
answered by 28.10.2016 в 23:23