Python Installation in local directory gives "ModuleNotFoundError": 'msvcrt' - python

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

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.

Related

Install Ansible Windows Machine

I have tried installing ansible through pip install ansible but whenever i get the following error trying to use it:
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\ruan.greyling\AppData\Local\Programs\Python\Python311\Scripts\ansible.exe\__main__.py", line 4, in <module>
File "C:\Users\ruan.greyling\AppData\Local\Programs\Python\Python311\Lib\site-packages\ansible\cli\__init__.py", line 42, in <module>
check_blocking_io()
File "C:\Users\ruan.greyling\AppData\Local\Programs\Python\Python311\Lib\site-packages\ansible\cli\__init__.py", line 34, in check_blocking_io
if not os.get_blocking(fd):
^^^^^^^^^^^^^^^
AttributeError: module 'os' has no attribute 'get_blocking'
I have python and pip installed on the machine.
It looks like this may be a version compatibility issue with Python 3.11. I recommend upgrading to the latest version of Python and then running the command again.
This is why you are getting this error.
Windows without WSL is not natively supported as a control node (more in the documentation)
If you want to run the Control node on Windows use WSL
Good practice code repository and sync to your Linux Control node from Windows machine.

Error installing mpi4py

I'm trying to install mpi4py and have followed the installation instructions using pip found here: http://mpi4py.scipy.org/docs/usrman/install.html#using-pip-or-easy-install
I'm running a virtualenv with python 2.7.10 on Mac OS 10.11.6, and have installed mpich3 using homebrew.
This is the error when I attempt to run a test:
Lorens-MBP:mpi4py-mpi4py-b9fccf29258a lorensheets$ ../bin/python test/runtests.py
Traceback (most recent call last):
File "test/runtests.py", line 257, in <module>
sys.exit(main())
File "test/runtests.py", line 244, in main
package = import_package(options, pkgname)
File "test/runtests.py", line 109, in import_package
import mpi4py.MPI
ImportError: dlopen(/Users/lorensheets/Desktop/fresh/virtual/lib/python2.7/site-packages/mpi4py/MPI.so, 2): Library not loaded: /
Users/lorensheets/opt/usr/local/lib/libmpi.20.dylib
Referenced from: /Users/lorensheets/Desktop/fresh/virtual/lib/python2.7/site-packages/mpi4py/MPI.so
Reason: image not found
Try installing openmpi instead of mpich3

Installing python module to Mac OS QGIS through console

My QGIS python console returns error
import tweepy
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 572, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
ImportError: No module named tweepy
I installed the python module to OS through pip but it is not available to QGIS python console. A previous question suggests it should have worked: Installing the Python geojson module on Mac OS X Yosemite to use with QGIS

fix PYTHONHOME in order to import liblas module in Python

I have the following error message on windows 64-bit and Python 2.7.
the liblas module version is libLAS-1.7.0.win-amd64-py2.7.‌exe
import liblas
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\lib\site-packages\liblas\__init__.py", line 2, in <module>
from core import get_version
File "C:\Python27\lib\site-packages\liblas\core.py", line 138, in <module>
las = ctypes.CDLL(os.path.join(local_dlls, lib_name))
File "C:\Python27\Lib\ctypes\__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 is not a valid Win32 application
The module is installed in
C:\Python27\Lib\site-packages\liblas
i used this module several times (it's a core module of my work), but today i have this problem. I unistalled liblas, reinstalled, unistalled all Python and all modules, and reinstall everything bit i have always the same problem.
If you have 64-bit version of Python installed and LibLAS dll 32-bit, then you can get this type of error. If so, then you can find 64-bit version of this library on this site (there are actually a lot of other 32-bit and 64-bit libraries for Python).

zc.buildout stopped working: ImportError: No module named apport.fileutils

I've been using buildout for quite a while now without any issue, in fact I did yesterday without any problems.
But as today all my projects fail to buildout. I tried on two different Ubuntu workstations with the same result.
This is the error I get:
Initializing zc.buildout
Debug: Downloading http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
Traceback (most recent call last):
File "bootstrap.py", line 259, in <module>
import zc.buildout.buildout
File "/tmp/tmpNkVMXW/zc.buildout-2.0.0-py2.7.egg/zc/buildout/buildout.py", line 18, in <module>
import zc.buildout.easy_install
File "/tmp/tmpNkVMXW/zc.buildout-2.0.0-py2.7.egg/zc/buildout/easy_install.py", line 59, in <module>
pkg_resources.Requirement.parse('distribute')
AttributeError: 'NoneType' object has no attribute 'location'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 66, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
ImportError: No module named apport.fileutils
Original exception was:
Traceback (most recent call last):
File "bootstrap.py", line 259, in <module>
import zc.buildout.buildout
File "/tmp/tmpNkVMXW/zc.buildout-2.0.0-py2.7.egg/zc/buildout/buildout.py", line 18, in <module>
import zc.buildout.easy_install
File "/tmp/tmpNkVMXW/zc.buildout-2.0.0-py2.7.egg/zc/buildout/easy_install.py", line 59, in <module>
pkg_resources.Requirement.parse('distribute')
AttributeError: 'NoneType' object has no attribute 'location'
It complains that there's no module named apport.fileutils .. but I get no exception when I run python and import it:
from apport.fileutils import likely_packaged, get_recent_crashes
2.0.0 just got released. The old bootstrap.py is not compatible with 2.0.0 but downloads it by default. You can get the v2 bootstrap.py from here, or use the code below if you want to stick with the old version.
python bootstrap.py -v 1.7.0
edit: older versions of v1 bootstrap.py don't allow version forcing. The up-to-date version here does.
The question + answer is from 2013. I recently (2015) saw it happening again.
The problem is that ubuntu's python-apport package installs a /usr/lib/python2.7/dist-packages/apport_python_hook.py file that overrides sys.excepthook. It makes sure python tracebacks are fed into ubuntu's "apport" error reporting mechanism.
That in itself is not a problem. But bootstrap.py restricts the python path, so that the hook cannot import apport anymore...
So if an error occurs during the bootstrap run, an exception is printed which then fails a second time because apport cannot be imported.
A solution could be to sudo apt-get remove python-apport. That's at least what we did on the server (where having apport makes no sense in any case).

Categories