Forums

switching default python version to 2.7

I've got a django setup that was moved from another site to pythonanywhere and it was using python 2.7 and when it tries to run on pythonanywhere, the version running it is 3.4, which breaks due to the missing MySQLdb module. I see where I could probably make it work with 3.4 but I'm thinking that there might be other reasons going forward that I would want to stay with 2.7, and I'm familiar with 2.7. Is it possible to set pythonanywhere to use 2.7 by default. If it's something that I can change, I haven't seen where to change it?

Hi there,

It depends what you mean by "default", and for what purposes.

If it's for the "Run" button on a Python file, you can set the python version using a hasbang. More info here: http://help.pythonanywhere.com/pages/SaveAndRunPythonVersion

For web apps, you choose your python version when you create it. If you've chosen the wrong one, you should delete and re-create your web app.

For the Bash command-line, the default "python" executable is 2.7, although you could probably change that with nifty use of symlinks in ~/.local/bin...

To get mysql working with django is fairly straightforward, you just need to install something called "mysqlclient":

https://help.pythonanywhere.com/pages/UsingMySQL/

If you're not using a virtualenv, I would definitely recommend that.

https://help.pythonanywhere.com/pages/VirtualEnvForNewerDjango

Hi there, my web app runs on python version 3.6 locally so I have created a new web app on PythonAnywhere dashboard for that purpose but on setting up my virtualenv, I realised the python version is 2.7.

Please should I still go ahead or can you tell me how I could change this to use the version of python I want.

Thanks.

yep, you should just create a new virtualenv with python3.6. the instructions here will tell you how. then you can delete the old virtualenv...

make sure your web app on the Web tab is also set up for python3.6. if it's not, again, delete it and re-create it...