0

I'm using my company's VM which already has Python 2.7 (comes with the OS) and Python 3.6.13 (Installed by the company)

Recently, there is a need to upgrade an application to latest version of Python ie: 3.10.2

So, I installed Python 3.10.2 in a local directory inside my $HOME. I referred to this link for the installation link.

While 2.7 & 3.6 are already there in the system.

Now, when I try to create a VENV with this python version (3.10.2), I see this error:

Traceback (most recent call last):
File "/export/home/sdc/python_versions/python310/python/lib/python3.10/subprocess.py", line 69, in <module>
    import msvcrt
ModuleNotFoundError: No module named 'msvcrt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/export/home/sdc/python_versions/python310/python/lib/python3.10/runpy.py", line 187, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/export/home/sdc/python_versions/python310/python/lib/python3.10/runpy.py", line 146, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/export/home/sdc/python_versions/python310/python/lib/python3.10/runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
  File "/export/home/sdc/python_versions/python310/python/lib/python3.10/venv/__init__.py", line 10, in <module>
    import subprocess
  File "/export/home/sdc/python_versions/python310/python/lib/python3.10/subprocess.py", line 74, in <module>
    import _posixsubprocess
ModuleNotFoundError: No module named '_posixsubprocess'

I found some solutions like this one: link but I cannot figure out how it will translate in my case since my installation directory is not /usr/local/... It is $HOME/path/to/dir

Aditya Chandel
  • 105
  • 1
  • 9

1 Answers1

0

Python on Linux does not have the msvcrt module at all. It's strictly Windows only. You seem to have miscompiled your Python somehow, since it also doesn't have the _posixsubprocess module (and msvcrt is used for Windows detection in subprocess.py).

May I recommend using pyenv or asdf for custom Python versions? They're less likely to miscompile Python.

AKX
  • 152,115
  • 15
  • 115
  • 172
  • I simply used the gzipped tarball from the official python website. Specifically: [https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tgz](https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tgz) . There is no suggestion of Windows or Linux here if my understanding is correct – Aditya Chandel Feb 23 '22 at 12:32
  • Your traceback and your question's tags imply this is a Linux VM, but you've somehow compiled it in a way that it doesn't include, or find, the `_posixsubprocess` module. I'm recommending using pyenv because then you won't need to deal with compiling anything by hand, but you still get user-level installs of various Python versions. – AKX Feb 23 '22 at 12:36