Как изменить версию python pythonanywhere

I am trying to deploy my Django application on pythonanywhere through manual-configuration. I selected Python 3.6.When I opened the console and type "python --version" It is showing python 2.7 inst...

I am trying to deploy my Django application on pythonanywhere through manual-configuration. I selected Python 3.6.When I opened the console and type «python —version» It is showing python 2.7 instead of 3.6. How can I change this?
Please help me.

asked Jun 30, 2017 at 5:32

Srinivas's user avatar

1

Python 3.6 is available as python3.6 in a console on PythonAnywhere.

answered Jun 30, 2017 at 16:03

Glenn's user avatar

GlennGlenn

7,1171 gold badge17 silver badges23 bronze badges

2

to set your default python version from 2.7 to 3.7 run the command below
$ alias python=python3
that’s it now check the version
$ python —version
it should be solved

answered Mar 7, 2019 at 18:01

naimur rahman's user avatar

you can check your python version in several way. Here are some way.

in Interpreter

>>import sys
>>sys.version
# output: python 3.6.0

in bash or console

python --version

Now for solving the version problem 2.x to 3.x

in your bash

$ alias python=python3

$ python —version

After doing this your environment for python it will interpret as python3

answered Jun 30, 2017 at 6:03

R.A.Munna's user avatar

R.A.MunnaR.A.Munna

1,6691 gold badge14 silver badges27 bronze badges

Try to type «python3 —version». This can work on linux, but I am not sure whether it works on pythonanywhere

answered Jun 30, 2017 at 5:42

Y.Liu's user avatar

Y.LiuY.Liu

541 silver badge7 bronze badges

How to change python version

I want to change to 3.6

deleted-user-5068057
|
1
post
|



Jan. 16, 2019, 8:08 p.m.

|
permalink

You can use any Python version you like; in bash, python will run 2.7, but python3.6 will run 3.6, and so on for other versions. If you’re trying to run 3.6 code somewhere else inside PythonAnywhere, let us know where it is and we can tell you exactly what you need to do.

Staff

giles
|
11190
posts
|

PythonAnywhere staff
|



Jan. 17, 2019, 11:25 a.m.

|
permalink

I have uploaded a script onto pythonanywhere and whenever i press Run in the upper right hand corner of the script, it always runs in Python 3.7. How do I make it run in 3.6?

deleted-user-6199701
|
24
posts
|



Sept. 23, 2019, 4:45 a.m.

|
permalink

Staff

fjl
|
3651
posts
|

PythonAnywhere staff
|



Sept. 23, 2019, 11:20 a.m.

|
permalink

This advise doesn’t seem to work. I’m trying to use the hashbang to switch to python 3.6: #!/usr/bin/python3.6

However, environment is still 3.8 when using save/run button, causing numpy issues:

File «/usr/lib/python3.8/site-packages/numpy/core/overrides.py», line 16, in <module>
add_docstring(
RuntimeError: implement_array_function method already has a docstring

I have 3.6 configured from my .bashrc but I don’t think it’s being sourced in that console. Am I missing something?

deleted-user-7317108
|
1
post
|



April 11, 2020, 5:54 p.m.

|
permalink

hmm- I would kill that python console and try to do a new save and run. do you mind pointing us to the file that this is happening in? (and for us to look at it?)

Staff

conrad
|
4233
posts
|

PythonAnywhere staff
|



April 12, 2020, 8:56 a.m.

|
permalink

please how can i change the default Python 2.7 in bash to 3.8?

piebeeper
|
4
posts
|



Aug. 18, 2020, 5:47 a.m.

|
permalink

Unfortunately the operating system requires that the command python should always run Python 2.7. But you can always run other versions by using the appropriate command, for example python3.8 for 3.8.

Staff

giles
|
11190
posts
|

PythonAnywhere staff
|



Aug. 18, 2020, 2:03 p.m.

|
permalink

I am having this problem too! and it has gotten very overwhelming. the system does not even build the wxPython , numpy . I defined python 3.6 as my work environment and it keeps giving me the console on python3.8. Any solution not involving me to continue spending days trying to get this solved will be appreciated. NONE of the solutions in the wiki, forums, help or anywhere else online has solved it. I have lost days in this issue. Please forward an intuitive step by step solution. The libraries run well in the stand alone python application so seems the problem may be pythonanywhere. I hope the team to have compassive human delicacy to respond.

SonoUno
|
1
post
|



Aug. 28, 2020, 12:50 p.m.

|
permalink

What do you mean by «keeps giving me the console on python3.8»? What are your exact steps?

Staff

fjl
|
3651
posts
|

PythonAnywhere staff
|



Aug. 28, 2020, 1:56 p.m.

|
permalink

Hi,

I have a similar issue where I cloned my GitHub repo and create a virtual environment with :
mkvirtualenv --python=/usr/bin/python3.8.5 crs_venv

Then when I want to install my packages, I run:
pip install -r requirements.txt

I get a depreciation warning and an error:
ERROR: ipykernel-5.3.4-py3-none-any.whl is not a supported wheel on this platform.

if I instead install using pip3, I get an error saying ERROR: Could not find a version that satisfies the requirement anaconda-client==1.7.2 (from -r requirements.txt (line 2)) (from versions:
1.1.1, 1.2.2)
ERROR: No matching distribution found for anaconda-client==1.7.2 (from -r requirements.txt (line 2))

Any help would be appreciated.

deleted-user-9244856
|
1
post
|



Jan. 3, 2021, 2:12 a.m.

|
permalink

What do you see if you run which pip when inside your virtualenv? It would also be interesting to know what you get if you run pip --version.

Staff

giles
|
11190
posts
|

PythonAnywhere staff
|



Jan. 3, 2021, 4:30 p.m.

|
permalink

Having the following error.

~/my_site/personal_web/mysite/my_app (main)$ python trial.py
Traceback (most recent call last):
  File "trial.py", line 37, in <module>
    with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
TypeError: __init__() got an unexpected keyword argument 'context'

This did not happen 2 months ago. I had made sure all of my codes were running, but now none of them do.

[edit by admin: formatting]

amaangigani35
|
2
posts
|



Feb. 26, 2021, 7:13 a.m.

|
permalink

Perhaps you were using a virtualenv earlier? When you’re not using a virtualenv, the command python will run Python 2.7 (which is unfortunately a requirement of the operating system).

I can see that your website is configured to use a virtualenv called myproj, so if you wan the code that you’re running from a Bash console to use that env, then you should first run the command

— once that is done, you’ll see (myproj) appear in the prompt in Bash, and the command python will be bound to the version of Python that your website uses, with all of the modules that you’ve installed into the virtualenv available.

Staff

giles
|
11190
posts
|

PythonAnywhere staff
|



Feb. 26, 2021, 3:55 p.m.

|
permalink

please I am having errors ModulenotFound error in the wsgi. could this be because of different python versions?

AlphaGuide
|
2
posts
|



Oct. 7, 2022, 11:50 p.m.

|
permalink

Make sure your web app is set up to use the same Python version / virtual environment you installed your modules for/to (or vice versa).

Staff

pafk
|
2446
posts
|

PythonAnywhere staff
|



Oct. 8, 2022, 7:44 a.m.

|
permalink

[updated for 2021]

(Regardless if you are on Mac, Linux, or Windows:)

If you are confused about how to start the latest version of python, on most platforms it is the case that python3 leaves your python2 installation intact (due to the above compatibility reasons); thus you can start python3 with the python3 command.

Historically…

The naming convention is that generally, most scripts will call python2 or python3 explicitly. This happened due to a need for backwards compatibility.

Even though technically python doesn’t even guarantee backwards compatibility between minor versions, Python3 really breaks backwards compatibility. At the time, programs invoking ‘python‘ were expecting python2 (which was the main version at the time). Extremely old systems may have programs and scripts which expect python=python2, and changing this would break those programs and scripts.

At the time this answer was written, OP should not have changed this due to maintaining compatibility for old scripts.

Circa year 2021…

Nowadays, many years after the python2->python3 transition, most software explicitly refers to python2 or python3 (at least on Linux). For example, they might call #!/usr/bin/env python2 or #!/usr/bin/env python3. This has for example (python-is-python3-package) freed up the python command to be settable to a user default, but it really depends on the operating system.

The prescription for how distributions should handle the python command was written up in 2011 as PEP 394 — The «python» Command on Unix-Like Systems. It was last updated in June 2019.

Basically if you are writing a library, you should specify the version of python (2 or 3, or finer-grained under specific circumstances) you can use. Otherwise as an end user, you should feel free to rename this for your own personal use (though your OS or distribution may not make that easy).

Shell alias:

You could, however, make a custom alias in your shell. The way you do so depends on the shell, but perhaps you could do alias py=python3, and put it in your shell startup file. This will only work on your local computer (as it should), and is somewhat unnecessary compared to just typing it out (unless you invoke the command constantly).

Confused users should not try to create aliases or virtual environments or similar that make python execute python3; this is poor form.This is acceptable nowadays, but PEP 394 suggests encouraging users to use a virtualenv instead.

Different 3.* versions, or 2.* versions:

In the extremely unlikely case that if someone comes to this question with two python3 versions e.g. 3.1 vs 3.2, and you are confused that you have somehow installed two versions of python, this is possibly because you have done manual and/or manual installations. You can use your OS’s standard package/program install/uninstall/management facilities to help track things down, and perhaps (unless you are doing dev work that surprisingly is impacted by the few backwards-incompatible changes between minor versions) delete the old version (or do make uninstall if you did a manual installation). If you require two versions, then reconfigure your $PATH variable so the ‘default’ version you want is in front; or if you are using most Linux distros, the command you are looking for is sudo update-alternatives. Make sure any programs you run which need access to the older versions may be properly invoked by their calling environment or shell (by setting up the var PATH in that environment).

A bit about $PATH

sidenote: To elaborate a bit on PATH: the usual ways that programs are selected is via the PATH (echo $PATH on Linux and Mac) environment variable. You can always run a program with the full path e.g. /usr/bin/🔳 some args, or cd /usr/bin then ./🔳 some args (replace blank with the ‘echo’ program I mentioned above for example), but otherwise typing 🔳 some args has no meaning without PATH env variable which declares the directories we implicitly may search-then-execute files from (if /usr/bin was not in PATH, then it would say 🔳: command not found). The first matching command in the first directory is the one which is executed (the which command on Linux and Mac will tell you which sub-path this is). Usually it is (e.g. on Linux, but similar on Mac) something like /usr/bin/python which is a symlink to other symlinks to the final version somewhere, e.g.:

% echo $PATH
/usr/sbin:/usr/local/bin:/usr/sbin:usr/local/bin:/usr/bin:/bin

% which python
/usr/bin/python
% which python2
/usr/bin/python2
% ls -l /usr/bin/python
lrwxrwxrwx 1 root root 7 Mar  4  2019 /usr/bin/python -> python2*
% ls -l /usr/bin/python2  
lrwxrwxrwx 1 root root 9 Mar  4  2019 /usr/bin/python2 -> python2.7*
% ls -l /usr/bin/python2.7
-rwxr-xr-x 1 root root 3689352 Oct 10  2019 /usr/bin/python2.7*

% which python3         
/usr/bin/python3
% ls -l /usr/bin/python3
lrwxrwxrwx 1 root root 9 Mar 26  2019 /usr/bin/python3 -> python3.7*
% ls -l /usr/bin/python3.7
-rwxr-xr-x 2 root root 4877888 Apr  2  2019 /usr/bin/python3.7*

% ls -l /usr/bin/python*
lrwxrwxrwx 1 root root       7 Mar  4  2019 /usr/bin/python -> python2*
lrwxrwxrwx 1 root root       9 Mar  4  2019 /usr/bin/python2 -> python2.7*
-rwxr-xr-x 1 root root 3689352 Oct 10  2019 /usr/bin/python2.7*
lrwxrwxrwx 1 root root       9 Mar 26  2019 /usr/bin/python3 -> python3.7*
-rwxr-xr-x 2 root root 4877888 Apr  2  2019 /usr/bin/python3.7*
lrwxrwxrwx 1 root root      33 Apr  2  2019 /usr/bin/python3.7-config -> x86_64-linux-gnu-python3.7-config*
-rwxr-xr-x 2 root root 4877888 Apr  2  2019 /usr/bin/python3.7m*
lrwxrwxrwx 1 root root      34 Apr  2  2019 /usr/bin/python3.7m-config -> x86_64-linux-gnu-python3.7m-config*
lrwxrwxrwx 1 root root      16 Mar 26  2019 /usr/bin/python3-config -> python3.7-config*
lrwxrwxrwx 1 root root      10 Mar 26  2019 /usr/bin/python3m -> python3.7m*
lrwxrwxrwx 1 root root      17 Mar 26  2019 /usr/bin/python3m-config -> python3.7m-config*

sidenote2: (In the rarer case a python program invokes a sub-program with the subprocess module, to specify which program to run, one can modify the paths of subprocesses with sys.path from the sys module or the PYTHONPATH environment variable set on the parent, or specifying the full path… but since the path is inherited by child processes this is not remotely likely an issue.)

Понравилась статья? Поделить с друзьями:
  • Как изменить версию postgresql
  • Как изменить версию php рег ру
  • Как изменить версию php на хостинге timeweb
  • Как изменить версию php на хостинге reg ru
  • Как изменить версию php на хостинге beget