Score:0

Having trouble opening a virtual environment in python3.9

cn flag

I have installed python3.9 through apt in my Ubuntu 18.04.6 LTS. Then I was trying to create a new virtual environment that runs on 3.9. This is the process I did:

$ python3.9 -m venv /home/user1/py3.9
Error: Command '['/home/user1/py3.9/bin/python3.9', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

To remedy this I tried upgrading pip, which raised an error regarding distutils. Here was the output of that:

$ python3.9 -m pip install --upgrade pip
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 188, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.9/runpy.py", line 147, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.9/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 29, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 23, in <module>
    from pip.locations import (
  File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in <module>
    from distutils import sysconfig
ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.9/distutils/__init__.py)

I then installed distutils using the command: sudo apt install python3.9-distutils, which was sucessful and after that I could upgrade pip. But I'm still having the same problem of returned non-zero exit status 1 if I try to create the virtual environment. I'm not sure what I did wrong. But I did install python3.11 in the past and could create virtual environment the same way IIRC. I'm not sure what to do at this point.

user535733 avatar
cn flag
Warning: It's been a great five years with Ubuntu 18.04. But it's coming to an end: We will stop answering questions about Ubuntu 18.04 in nine days. Now might be a good time to migrate to a newer release of Ubuntu.
guiverc avatar
cn flag
Online tools like https://packages.ubuntu.com/ no longer provide details for anything older than 20.04 as the five years of support for *bionic* or 18.04 ended last month, so our ability to help is even more limited now. We'd need to have a *bionic* system around (to do enquiries at terminal) or have *devscripts* installed that allow searching of ESM releases such as 18.04 (*18.04 ESM official start date is 31-May-2023 so you're on-topic on this site until then*). I'd suggest planning your *release-upgrade* asap too.
ponir avatar
cn flag
Thanks a lot. I did work out my own solution eventually. I guess from my part it was more of an inexperience. Also, I think it doesn't matter what ubuntu I'm using. The problem/solution should be same.
Score:1
cn flag

Just installing python isn't enough. You have to to multiple steps:

sudo apt install python3.9
sudo apt install python3.9-distutils
sudo apt install python3.9-venv

Hopefully, after that everything will work as intended.

user535733 avatar
cn flag
Hmmm. `-distutils` should have been included with a stock install. Most users should simply install Ubuntu, then install `python3.x-venv`. That's all they need.
ponir avatar
cn flag
Yeah. Dev is probably not needed. But I needed that for some other pip install stuff later. I edited and deleted that line.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.