Im looking to download modules on Python but I seem to be running into some problems. Whenever I import a new module, an error always shows up. Here is an example of the code that I am using to download a module:
import openpyxl
and this is the error that shows up when I try to run this code:
Traceback (most recent call last):
File "/Users/jonathankent/PycharmProjects/untitled/HelloWorld/automation.py", line 1, in <module>
import openpyxl
File "/Users/jonathankent/PycharmProjects/untitled/HelloWorld/venv/lib/python3.8/site-packages/openpyxl/__init__.py", line 4, in <module>
from openpyxl.compat.numbers import NUMPY, PANDAS
File "/Users/jonathankent/PycharmProjects/untitled/HelloWorld/venv/lib/python3.8/site-packages/openpyxl/compat/__init__.py", line 4, in <module>
from .strings import safe_string
File "/Users/jonathankent/PycharmProjects/untitled/HelloWorld/venv/lib/python3.8/site-packages/openpyxl/compat/strings.py", line 4, in <module>
from math import isnan, isinf
ImportError: cannot import name 'isnan' from 'math' (/Users/jonathankent/PycharmProjects/untitled/HelloWorld/math.py)
Process finished with exit code 1
If anyone knows what could be causing this please let me know.
ImportError: cannot import name 'isnan' from 'math' (/Users/jonathankent/PycharmProjects/untitled/HelloWorld/math.py)
It seems you have named your own module math. This shadows the built-in math module.
The error means that some other code wanted to import the built-in math module but found your module instead.
The simplest solution would be if you named your module differently.
Related
I have a python script that uses the lib awswrangler. Today my scrpit started to give errors in the import of the library and I don't know what is happening.
I'm running the script in a docker container with image python: 3.8
Example:
import awswrangler as wr
print(wr.__version__)
Error:
Traceback (most recent call last):
File "src/avec/automation/TaskBaseUserPass.py", line 1, in <module>
from awswrangler.pandas import Pandas
File "/usr/local/lib/python3.8/site-packages/awswrangler/__init__.py", line 17, in <module>
from awswrangler.pandas import Pandas # noqa
File "/usr/local/lib/python3.8/site-packages/awswrangler/pandas.py", line 45, in <module>
class Pandas:
File "/usr/local/lib/python3.8/site-packages/awswrangler/pandas.py", line 273, in Pandas
def _read_csv_once_remote(send_pipe: mp.connection.Connection, session_primitives: "SessionPrimitives",
AttributeError: module 'multiprocessing' has no attribute 'connection'
I have been experienced the same issue today when trying to import awswrangler. For me, downgrading the following dependencies helped:
pip install fsspec==0.6.3 PyAthena==1.10.2 s3fs==0.4.0
It seems that one or more of them were causing the problem.
If your code uses multiprocessing.connection.Listener or multiprocessing.connection.Client, then you should use:
import multiprocessing.connection
If you just use
import multiprocessing
.. then your code might get an ImportError or not. It depends on other modules. If an other module imports multiprocessing.connection, then it will work.
But I guess you don't want random behavior, and that's why you should import multiprocessing.connection.
I managed to run version 3.6, the library has a problem with mp.connection.Connection in current python versions
I can use the module correctly by Python, but when using Jython, some error occurs...
Code:
from jieba import *
Errors:
Traceback (most recent call last):
File "/Users/Jack/Documents/workspace/FirstJython/hellojyphon.py", line 8, in <module>
from jieba import *
File "/Users/Jack/Documents/workspace/FirstJython/jieba/__init__.py", line 15, in <module>
from ._compat import *
ImportError: No module named _compat
Is there any differences between Python and Jython when import?
I solve it by myself.
There is something wrong when using relative directories in Jython.
so after I change ._compat to jieba._compat, the problem solved!
But I don't exactly know the reason...
This question already has answers here:
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed 6 years ago.
I have a Python script that uses requests. It worked fine for a long time. Now out of the blue I get the following error. I tried reinstalling requests but that didn't fix it. The only thing I can think of that caused the error is I have been running a Django development server, so maybe I got hacked? Please help.
code:
import requests
...
error:
Traceback (most recent call last):
File "myfile.py", line 1, in <module>
import requests
File "/Users/myuser/.virtualenvs/mysite/lib/python2.7/site-packages/requests/__init__.py", line 58, in <module>
from . import utils
File "/Users/myuser/.virtualenvs/mysite/lib/python2.7/site-packages/requests/utils.py", line 12, in <module>
import cgi
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/cgi.py", line 50, in <module>
import mimetools
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
import tempfile
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 35, in <module>
from random import Random as _Random
ImportError: cannot import name Random
You have masked the built-in library module with a local file named random.py. Rename that file.
Python looks up modules to import along a path, and if you put a module in a location that's looked at before the standard library, you can end up masking a built-in like you did here.
as from title, if I try to import ctypes in nuke6.1v2 I get this error:
import ctypes
# Result: Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\Nuke6.1v2\lib\ctypes\__init__.py", line 10, in <module>
from _ctypes import Union, Structure, Array
ImportError: No module named _ctypes
I also tryed to import it from the Python 2.6 main folder but with no luck.
However, if I try to import it in another package (softimage for example) I have no problem at all.
I have found a lot of people having the same problem, but none of the solutions worked for me.
Any idea?
Thanks
I have a funny problem I'd like to ask you guys ('n gals) about.
I'm importing some module A that is importing some non-existent module B. Of course this will result in an ImportError.
This is what A.py looks like
import B
Now let's import A
>>> import A
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/importtest/A.py", line 1, in <module>
import B
ImportError: No module named B
Alright, on to the problem. How can I know if this ImportError results from importing A or from some corrupt import inside A without looking at the error's string representation.
The difference is that either A is not there or does have incorrect import statements.
Hope you can help me out...
Cheers bb
There is the imp module in the standard lib, so you could do:
>>> import imp
>>> imp.find_module('collections')
(<_io.TextIOWrapper name=4 encoding='utf-8'>, 'C:\\Program Files\\Python31\\lib\\collections.py', ('.py', 'U', 1))
>>> imp.find_module('col')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
imp.find_module('col')
ImportError: No module named col
which raises ImportError when module is not found. As it's not trying to import that module it's completely independent on whether ImportError will be raised by that particular module.
And of course there's a imp.load_module to actually load that module.
You can also look at the back-trace, which can be examined in the code.
However, why do you want to find out - either way A isn't going to work.