How to fix 'No module named Mpi4py' when I installed mpi4py - openmpi

so I installed openmpi and the mpi4py library (I made sure to install the python3 version as that gave me an error earlier) and the mpi4py library still cannot be found by my python programs.
I tried installing it again using pip3 and that didn't work, also none of the other questions seem to have helped.
import mpi4py
And this is the error:
Input xml: /home/robotics/spinningup/half_cheetah_variable.xml
Output xml: /home/robotics/gym/gym/envs/mujoco/assets/half_cheetah.xml
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "/home/robotics/spinningup/spinup/__init__.py", line 2, in <module>
from spinup.algos.ddpg.ddpg import ddpg
File "/home/robotics/spinningup/spinup/algos/ddpg/ddpg.py", line 7, in <module>
from spinup.utils.logx import EpochLogger
File "/home/robotics/spinningup/spinup/utils/logx.py", line 14, in <module>
from spinup.utils.mpi_tools import proc_id, mpi_statistics_scalar
File "/home/robotics/spinningup/spinup/utils/mpi_tools.py", line 1, in <module>
from mpi4py import MPI

Related

How do I fix this 'ModuleNotFoundError: No module named 'pip._internal.models.target_python'?

I am new to python and was testing some things out I had seen online.
from selenium import webdriver
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://techwithtim.net")
But I get the following error message:
Traceback (most recent call last):
File "C:\Users\absol\PycharmProjects\pythonProject\test.py", line 2, in <module>
from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'
Process finished with exit code 1
I have already successfully used pip install selenium and other variations which after trying to repeat them they inform me that requirements are already met. IDLE will tell me the selenium version when I ask for it.
I then tried the "Python Packages" tab to manually install selenium but it returns the following error message:
File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3\plugins\python-ce\helpers\packaging_tool.py", line 73, in run_pip
runpy.run_module(module_name, run_name='__main__', alter_sys=True)
File "<frozen runpy>", line 226, in run_module
File "<frozen runpy>", line 98, in _run_module_code
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\absol\PycharmProjects\pythonProject\venv\Lib\site-packages\pip\__main__.py", line 29, in <module>
from pip._internal.cli.main import main as _main
File "C:\Users\absol\PycharmProjects\pythonProject\venv\Lib\site-packages\pip\_internal\cli\main.py", line 9, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "C:\Users\absol\PycharmProjects\pythonProject\venv\Lib\site-packages\pip\_internal\cli\autocompletion.py", line 10, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "C:\Users\absol\PycharmProjects\pythonProject\venv\Lib\site-packages\pip\_internal\cli\main_parser.py", line 8, in <module>
from pip._internal.cli import cmdoptions
File "C:\Users\absol\PycharmProjects\pythonProject\venv\Lib\site-packages\pip\_internal\cli\cmdoptions.py", line 29, in <module>
from pip._internal.models.target_python import TargetPython
ModuleNotFoundError: No module named 'pip._internal.models.target_python'
And it suggests to run the following:
(venv) C:\Users\absol>C:\Users\absol\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Program Files/JetBrains/PyCharm Community Edition 2022.3/plugins/python-ce/helpers/packaging_tool.py install selenium
Which returns this:
(c) Microsoft Corporation. All rights reserved.
C:\Users\absol>C:\Users\absol\PycharmProjects\pythonProject\venv\Scripts\activate.bat
(venv) C:\Users\absol>C:\Users\absol\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Program Files/JetBrains/PyCharm Community Edition 2022.3/plugins/python-ce/helpers/packaging_tool.py install selenium
C:\Users\absol\AppData\Local\Programs\Python\Python311\python.exe: can't open file 'C:\\Program': [Errno 2] No such file or directory
(venv) C:\Users\absol>pip install selenium
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\absol\PycharmProjects\pythonProject\venv\Scripts\pip.exe\__main__.py", line 4, in <module>
File "C:\Users\absol\PycharmProjects\pythonProject\venv\Lib\site-packages\pip\_internal\cli\main.py", line 9, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "C:\Users\absol\PycharmProjects\pythonProject\venv\Lib\site-packages\pip\_internal\cli\autocompletion.py", line 10, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "C:\Users\absol\PycharmProjects\pythonProject\venv\Lib\site-packages\pip\_internal\cli\main_parser.py", line 8, in <module>
from pip._internal.cli import cmdoptions
File "C:\Users\absol\PycharmProjects\pythonProject\venv\Lib\site-packages\pip\_internal\cli\cmdoptions.py", line 29, in <module>
from pip._internal.models.target_python import TargetPython
ModuleNotFoundError: No module named 'pip._internal.models.target_python'
*Note: I went ahead and tried pip install selenium again just because I saw the (venv)
At this point I just don't know where I should be looking. I thought maybe I just don't know how to deal with PyCharm virtual environments and should change to a different script writer. I would be open to that, or just a link to a comprehensive guide for me to read over how to fix PyCharm.
Any help or direction to some kind of video media is appreciated.
Edit/Update: I am able to run the code through IDLE and Jupyter. Although still get a "deprecation" message:
driver = webdriver.Chrome(PATH)
Try this commmand.
python -m pip install --upgrade pip

when install any package using pip i get error can't import mapping from collection?

I work on python 3.10 i face error and i can't solve it .
this error display when try to install new package or
using any pip related command
python 3.10 already installed but can't add New Package using pip
this error as below got it from command prompt
C:\Program Files\Python310>pip list
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Program Files\Python310\Scripts\pip.exe\__main__.py", line 4, in <module>
File "C:\Users\sa\AppData\Roaming\Python\Python310\site-packages\pip\__init__.py", line 21, in <module>
from pip._vendor.urllib3.exceptions import DependencyWarning
File "C:\Users\sa\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "C:\Users\sa\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\urllib3\connectionpool.py", line 29, in <module>
from .connection import (
File "C:\Users\sa\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\urllib3\connection.py", line 39, in <module>
from .util.ssl_ import (
File "C:\Users\sa\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\urllib3\util\__init__.py", line 3, in <module>
from .connection import is_connection_dropped
File "C:\Users\sa\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\urllib3\util\connection.py", line 3, in <module>
from .wait import wait_for_read
File "C:\Users\sa\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\urllib3\util\wait.py", line 1, in <module>
from .selectors import (
File "C:\Users\sa\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\urllib3\util\selectors.py", line 14, in <module>
from collections import namedtuple, Mapping
ImportError: cannot import name 'Mapping' from 'collections' (C:\Program Files\Python310\lib\collections\__init__.py)
so what i do to solve issue please ?
Last Updated Post
I delete folder urllib3 from path and execute command below to reinstall again .
but i get error as
C:\Users\sa\AppData\Roaming\Python\Python310\site-packages\pip\_vendor>pip install -U urllib3
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Program Files\Python310\Scripts\pip.exe\__main__.py", line 4, in <module>
File "C:\Users\sa\AppData\Roaming\Python\Python310\site-packages\pip\__init__.py", line 21, in <module>
from pip._vendor.urllib3.exceptions import DependencyWarning
ModuleNotFoundError: No module named 'pip._vendor.urllib3'
this is collections init.py file
https://pastebin.com/ADc9dV3b
so what i modify or on which place i will modify
From Python 3.3 to 3.9, import Mapping from collections raised a DeprecationWarning:
DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working
Since Python 3.10, it doesn't work anymore. It looks like you are using an old version of urllib3 because the selector.py file exists only on versions 1.20, 1.21 and 1.22. The current version is 1.26.
Upgrade urllib3 should solve the problem:
[...]# pip install -U urllib3
Update
Maybe you can remove manually the urllib3-X.Y.Z.dist-info and urllib3 folders in C:\Users\sa\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\. After that reinstall urllib3.
Try editing the file
(C:\Program Files\Python310\lib\collections_init_.py )
and add to the import
from collections.abc import Mapping
Just add to collections (.abc)
To get collections.abc

Spacy_DLL load failed while importing nn_parser

I am trying to download the french module for Spacy with the command python -m spacy download fr_core_news_md , but it get error:
Traceback (most recent call last):
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 184, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 143, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 110, in _get_module_details
__import__(pkg_name)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\spacy\__init__.py", line 12, in <module>
from . import pipeline
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38\lib\site-packages\spacy\pipeline\__init__.py", line 4, in <module>
from .pipes import Tagger, DependencyParser, EntityRecognizer, EntityLinker
File "pipes.pyx", line 1, in init spacy.pipeline.pipes
ImportError: DLL load failed while importing nn_parser: The specified module could not be found.
How to fix it?
Python 3.8.2 (64 bit) on Windows 10*64
Thank you!
I managed to fix this error by installing Visual C++ redist on my Windows machine.
https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
I also managed to fix this by installing the MS VC redist package. If you use, chocolately: https://chocolatey.org/packages/vcredist140
choco install vcredist140

Why can't Jupyter notebook open Kernel?

I recently installed Jupyter on a new computer and after trying with and without virtualenv, I receive the following errors related to the threading module. This error prevents the notebook from either (1) opening or (2) starting the kernel.
Error upon opening python -m notebook. Notebook doesn't open successfully.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/notebook/__init__.py", line 25, in <module>
from .nbextensions import install_nbextension
File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/notebook/nbextensions.py", line 31, in <module>
from .config_manager import BaseJSONConfigManager
File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/notebook/config_manager.py", line 15, in <module>
from traitlets.config import LoggingConfigurable
File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/traitlets/config/__init__.py", line 6, in <module>
from .application import *
File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/traitlets/config/application.py", line 11, in <module>
import logging
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/__init__.py", line 210, in <module>
_lock = threading.RLock()
AttributeError: module 'threading' has no attribute 'RLock'
Exception ignored in: <module 'threading' from '/Users/me/Downloads/threading.py'>
AttributeError: module 'threading' has no attribute '_shutdown'
Error after switching directory, opening notebook successfully, and attempting to connect to kernel
[I 09:32:05.828 NotebookApp] KernelRestarter: restarting kernel (3/5), new random ports
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/ipykernel_launcher.py", line 15, in <module>
from ipykernel import kernelapp as app
File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/ipykernel/__init__.py", line 2, in <module>
from .connect import *
File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/ipykernel/connect.py", line 13, in <module>
from IPython.core.profiledir import ProfileDir
File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/IPython/__init__.py", line 54, in <module>
from .core.application import Application
File "/Users/me/Documents/Code/Python/Environments/Jupyter/lib/python3.7/site-packages/IPython/core/application.py", line 18, in <module>
import logging
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/__init__.py", line 210, in <module>
_lock = threading.RLock()
AttributeError: module 'threading' has no attribute 'RLock'
Exception ignored in: <module 'threading' from '/Users/me/Downloads/threading.py'>
AttributeError: module 'threading' has no attribute '_shutdown'
Seeing as threading is a built-in module, I cannot update it. Again, this result is identical using the normal site-packages installation and a clean virtualenv installation.
I found that this error was caused because a file named threading.py (not related to the built-in module) existed in a subdirectory of my home directory. If I launched the notebook from any directory where the file was anywhere in the directory tree below my current directory, I would receive this error.
The solution is to launch the notebook in a directory where a naming conflict with the built-in threading does not exist.
The odd thing is that if I import threading in a Python shell in the same directories where the failures occurred and run dir(threading), it picks up the correct package. Why does Jupyter treat this differently?

Why am I getting invalid syntax error while installing packages with pip

In Debian server when I am installing boto3 using pip I get the following error:
$ python3.2 -m pip install boto3
Traceback (most recent call last):
File "/usr/lib/python3.2/runpy.py", line 161, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python3.2/runpy.py", line 74, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.2/dist-packages/pip/__main__.py", line 16, in <module>
from pip._internal import main as _main # isort:skip # noqa
File "/usr/local/lib/python3.2/dist-packages/pip/_internal/__init__.py", line 40, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/local/lib/python3.2/dist-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/local/lib/python3.2/dist-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
from pip._internal.cli import cmdoptions
File "/usr/local/lib/python3.2/dist-packages/pip/_internal/cli/cmdoptions.py", line 17, in <module>
from pip._internal.locations import USER_CACHE_DIR, src_prefix
File "/usr/local/lib/python3.2/dist-packages/pip/_internal/locations.py", line 13, in <module>
from pip._internal.utils import appdirs
File "/usr/local/lib/python3.2/dist-packages/pip/_internal/utils/appdirs.py", line 12, in <module>
from pip._internal.utils.compat import WINDOWS, expanduser
File "/usr/local/lib/python3.2/dist-packages/pip/_internal/utils/compat.py", line 62
return u"".join(u"\\x%x" % c for c in raw_bytes), err.end
^
SyntaxError: invalid syntax
Note: pip version is 18.1
I figured it out. The syntax - u"".join is not supported in python3.2.
pip3(which was same as pip3.2) while running the scripts for installing boto3 faced the syntax and threw the exception.
I installed python 3.6 and on running "pip3.6 install boto3", it worked.
Note: My python project is new and small one, so changing from python3.2 to python3.6 did not affect much, but with large or existing project this may not be feasible. Just want anyone who may face the situation to know the reason for this issue.

Resources