Correctly configure python3.8.6 or .7 on debian stretch for a django project

Hello,

My subject may not be in the correct category, I apologize in advance.

I have a php application in production hosted on a debian (stretch) server - plesk dedicated server. This server runs with apache and nginx in reverse proxy mode.

I have just finalized in my local environment (ubuntu 18.04) a django application (3.1.4) that I have to deploy on this debian server. On the latter, are installed python 2.7 and 3.5. Python 3.5 is not compatible with my django application.

As my django application and its dependencies in the local environment run with python 3.8.7, I decided to install python 3.8.6 on the debian server.

While doing this (I sure did wrong) I get error messages when trying to configure my django and / or python3.8 application.

Here are the actions taken on debian:
I copied my django project to a directory on the server and installed python3.8.6. However when I try to install virtualenv (pip3 install virtualenv) I get the following error message:

Traceback (most recent call last):
File « /usr/bin/pip3 », line 9, in
from pip import main
ImportError: cannot import name ‹ main › from ‹ pip › (/usr/local/lib/python3.8/site-packages/pip/ init .py)

Need help to be able to properly configure python3.8 without disturbing my application in production.

Thank you in advance

how did you install python3.8? Did you build from source or install one of the deadsnake packages?

What was the full command you issued to try to install virtualenv?

cd /opt/
wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz
tar xzf Python-3.8.6.tgz
cd Python-3.8.6/
./configure --enable-optimizations
make altinstall
pip3 install virtualenv

My base recommendation is to try and install from a debian repo. (Experimental? Unstable? You might want to check both) Despite the names, I’ve found that that works better for me than trying to build from source.

However, if you really want to work from a source build:

I’m going to assume you did a make before make altinstall, and that you did the make altinstall as root.

You should then be able to verify that it’s installed and basically functional by just running python3.8 to verify that an interactive session works.

Since you’re building from source, you might need to bootstrap your way through to pip, which means building pip from source yourself for your new environment. (I’m not sure what tools & utilities are all currently included in a source build.) There may be other libraries as well that you’ll need to build before you have a fully functional environment.

How to switch Python versions

Ubuntu 20.04 does not use 2.x for the environment, you have to install it separately.

Using the instructions in the link you can switch between the two and create your virtual environments. After being created, activate the venv then run pip (no need to call pip(version) as your doing)

I hope this helps