Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting an import error for importing process on python 3.3?

I am receiving the following error when importing Process in python 3.3. Is there any reason I would get such an error, or is this a bug? I am running the django server in another terminal window, but I doubt that would have anything to do with this.

Python 3.3.2 (default, Nov  8 2013, 13:38:57) 
[GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
# extension module loaded from '/usr/lib64/python3.3/lib-dynload/readline.cpython-33m.so'
import 'readline' # <_frozen_importlib.ExtensionFileLoader object at 0x7f8a00fc1050>
>>> from multiprocessing import Process
# ./__pycache__/multiprocessing.cpython-33.pyc matches ./multiprocessing.py
# code object from ./__pycache__/multiprocessing.cpython-33.pyc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1567, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1534, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 586, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1024, in load_module
  File "<frozen importlib._bootstrap>", line 1005, in load_module
  File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 870, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "./multiprocessing.py", line 1, in <module>
    from multiprocessing import Process
ImportError: cannot import name Process
like image 400
user1876508 Avatar asked Dec 18 '13 21:12

user1876508


People also ask

How do you fix an import error in Python?

Python's ImportError ( ModuleNotFoundError ) indicates that you tried to import a module that Python doesn't find. It can usually be eliminated by adding a file named __init__.py to the directory and then adding this directory to $PYTHONPATH .

What is meaning of import error in Python?

In Python, ImportError occurs when the Python program tries to import module which does not exist in the private table. This exception can be avoided using exception handling using try and except blocks. We also saw examples of how the ImportError occurs and how it is handled.

Why can't I import modules in Python?

This is caused by the fact that the version of Python you're running your script with is not configured to search for modules where you've installed them. This happens when you use the wrong installation of pip to install packages.

Why do I need __ init __ py?

The __init__.py files are required to make Python treat directories containing the file as packages. This prevents directories with a common name, such as string , unintentionally hiding valid modules that occur later on the module search path.


1 Answers

The line File "./multiprocessing.py" in your traceback suggests that you have a file named multiprocessing.py in the working directory.

Try removing/renaming it, because it shadows the real multiprocessing module. The problem here is that the very first entry in your sys.path is always '', so a file in the working dir will be preferred to a standard module when doing an import.

like image 190
Lev Levitsky Avatar answered Sep 18 '22 08:09

Lev Levitsky