python 2 vs 3 problem?

I have a flask site that works perfectly on my own machine. It was programmed with python 3. I cloned it on my linode.

when I run gunicorn -b localhost:8000 -w 4 my_website:app, I get an error.

I believe this is the source of the error:
t3=pickle.load(handle)
File "/usr/lib/python2.7/pickle.py", line 1384, in load
return Unpickler(file).load()
File "/usr/lib/python2.7/pickle.py", line 864, in load
dispatchkey
File "/usr/lib/python2.7/pickle.py", line 892, in load_proto
raise ValueError, "unsupported pickle protocol: %d" % proto
ValueError: unsupported pickle protocol: 3

As you see, I get an error when the script attempts to unpickle an object. Is my linode trying to run python 2 instead of 3? Please advise me on what to do. I am a beginner and will appreciate your patience.

6 Replies

What distro are you running?

I am running Ubuntu 16.04

Ok check this guide. You might just need to set the default Python version to 3. [https://linuxconfig.org/how-to-change-default-python-version-on-debian-9-stretch-linux

404 error on that link.

But I get what you are saying. I'll try to set the default to python 3, and report back.

Thank you.

I have set the default to python 3 using the alias creating method. I can confirm python 3 is the default since
$ python --version
returns python 3.5.2

Unfortunately, this did not solve my problem. I get the same error message.

You may want to set up a virtualenv for your site's code.

Second, it seems that gunicorn has its own python version selection mechanism whcih defaults to 2.7 independently of the system default:

https://stackoverflow.com/questions/23928213

PS - personally I use a combination of nginx + virtualenv + uwsgi to run a Flask site in production… works well.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct