Python 3.5+ support is a little rough - here's a workaround

django
python

#1

Hello, I am playing around with Django 2 (pre-release) which will require Python 3.5 or 3.6. I tried both a Python and a plain Ubuntu workspace and both had a couple issues. Here is what I did to work around them, but it would be great if there was an improved workspace.

First, /usr/bin/python3 points to python 3.4, despite python 3.5 being installed and python 3.6 being available from a PPA. So I uninstalled python3.4 and python3.4-minimal using sudo apt-get remove python3.4 python3.4-minimal then I cleaned up dangling dependencies using sudo apt-get autoremove.

If you want to use Python 3.5 then stop here, but if you want to upgrade to Python 3.6 then repeat the process for python3.5 and python3.5-minimal then install python 3.6 using sudo apt-get install python3.6 python3.6-venv.

Now you may be tempted to do something like this: pip install django, but don’t do it. That will use Python 2.7. Likewise you may want to use pip3 install django but, sadly, pip3 went away when we removed python 3.4.

So then you may think, “well, I’ll do it the modern way,” and run python3.5 -m pip install django, which is actually the right thing to do, but this does not work. :frowning: You instead get this error (same is true with python 3.6):

usr/bin/python3.5: No module named pip

The only workaround I know of is to create a virtualenv, which when doing local development is a good practice. I’d consider it unnecessary when using single purpose VMs or containers, like I think is happening with C9 behind the scenes, but whatever.

Create a virtualenv pyvenv-3.5 venv, in this case my virtualenv is called ‘venv’, and then activate it using . venv/bin/activate. This will now switch on my virtual environment. You’ll need to do this each time you open a new terminal.

Now you can use pip, or pip3 or pip3.5/pip3.6 and install Django or whatever other package you expect. For example, you can clone django 2 using git clone https://github.com/django/django.git and then pip install django and you’ll get the latest development version.

Expected behavior

You should be able to run python -m pip install something to install ‘something’. I’m not sure why this doesn’t work in the Python workspace or the plain Ubuntu workspace. When I look in site-packages on Python 3.5 or Python 3.6 it is completely empty. That is why there’s an error with python3.5 -m pip…. There is probably some package needed but not installed. Maybe it conflicts with a python 2.7 package.

I would also expect that Python 3.4 would be gone, since there are now two newer versions. Maybe this is also a dependency thing. It would be great if /usr/bin/python3 pointed at 3.5 or 3.6 and pip3 worked the same. I realize that pip3 is deprecated in favor of python -m pip, so this is not that big of a deal.

Likewise, pyvenv is also deprecated in favor of python -m venv, so presumably, whatever fixes pip will also fix venv.

Hopefully this helps someone.