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?
Related
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
I am trying to replicate the experiments from https://github.com/QData/spacetimeformer.
After creating the environment and running the script provided in the Example Spacetimeformer Training Commands section of the repo, I get the following stack trace:
Traceback (most recent call last):
File "train.py", line 7, in <module>
import pytorch_lightning as pl
File "/home/fsuser/miniconda3/envs/spacetimeformer/lib/python3.8/site-packages/pytorch_lightning/__init__.py", line 30, in <module>
from pytorch_lightning.callbacks import Callback # noqa: E402
File "/home/fsuser/miniconda3/envs/spacetimeformer/lib/python3.8/site-packages/pytorch_lightning/callbacks/__init__.py", line 14, in <module>
from pytorch_lightning.callbacks.base import Callback
File "/home/fsuser/miniconda3/envs/spacetimeformer/lib/python3.8/site-packages/pytorch_lightning/callbacks/base.py", line 21, in <module>
import torch
File "/home/fsuser/.local/lib/python3.8/site-packages/torch/__init__.py", line 196, in <module>
_load_global_deps()
File "/home/fsuser/.local/lib/python3.8/site-packages/torch/__init__.py", line 149, in _load_global_deps
ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)
File "/home/fsuser/miniconda3/envs/spacetimeformer/lib/python3.8/ctypes/__init__.py", line 369, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /home/fsuser/.local/lib/python3.8/site-packages/torch/lib/libtorch_global_deps.so: cannot open shared object file: No such file or directory
The same stack trace is replicable by simply importing torch in a .py script.
I've checked /home/fsuser/.local/lib/python3.8/site-packages/torch/lib/ and there is no libtorch_global_deps.so file. Do I have to pull it from somewhere or install some other torch library?
I'm running this code on Ubuntu 20.04, python3.8 torch1.9.0 and cuda 10.2.
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
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.
The following output appeared when I was attempting to start an instance of the Jupyter botebook:
C:\Users\CaitlinG>jupyter notebook
Traceback (most recent call last):
File "c:\users\caitling\appdata\local\programs\python\python35\lib\runpy.py",
line 184, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\caitling\appdata\local\programs\python\python35\lib\runpy.py",
line 85, in _run_code
exec(code, run_globals)
File "C:\Users\CaitlinG\AppData\Local\Programs\Python\Python35\Scripts\jupyter
-notebook.exe\__main__.py", line 5, in <module>
File "c:\users\caitling\appdata\local\programs\python\python35\lib\site-packag
es\notebook\notebookapp.py", line 31, in <module>
from zmq.eventloop import ioloop
File "c:\users\caitling\appdata\local\programs\python\python35\lib\site-packag
es\zmq\__init__.py", line 37, in <module>
_libzmq = ctypes.cdll.LoadLibrary(bundled[0])
File "c:\users\caitling\appdata\local\programs\python\python35\lib\ctypes\__in
it__.py", line 425, in LoadLibrary
return self._dlltype(name)
File "c:\users\caitling\appdata\local\programs\python\python35\lib\ctypes\__in
it__.py", line 347, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
I am using Windows 10 and Python 3.5.2. I installed the package, along with its dependencies, via: pip3 install "ipython[notebook]" --upgrade
The aforementioned process proceeded without incident but I am confused why the issue has appeared.
Thanks.
It seems to be an issue with pyzmq 15.3. Installing a previous version worked for me:
pip install pyzmq==15.2
See:
https://github.com/jupyter/help/issues/62
Good luck!