I am new to python and the getopt function. I am trying to import getopt, however I run into an error.
My code is literally just:
import getopt
and also tried
from getopt import * /// from getopt import getopt
Output below:
python asdfasdf.py
ARGV : []
Traceback (most recent call last):
File "asdfasdf.py", line 1, in <module>
import getopt
File "/home/STUDENTS/~~/csc328/TCP/pyExample/getopt.py", line 12, in <module>
'version=',
TypeError: 'module' object is not callable
My python is 2.6 something and this was implemented in 2.3 I believe.
edit: I'm using unix
you might be have getotp module in your code. When you refere python third party module, it try to import your module.
Pleas remove getopt.py in your example or rename it.
Related
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.
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'm using Python 3.6.4 with Miniconda on MacOS. I'm curious about that I can use methods that belongs to re module after I import tkinter. For example, if I want to use a re method without importing it:
>>> re.compile('abc')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 're' is not defined
But if I use a re methods after importing tkinter, it works properly, like:
>>> from tkinter import *
>>> re.compile('abc')
re.compile('abc')
So I can use re.compile() even if I haven't done import re. Why does it happen?
From the tkinter Source in line 39:
import re
So when you import the Module tkinter you automaticly import re with it
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...
I am trying to use z3 in pydev, I add the path of z3py and libz3.dll to window/preferences/pydev/jython-interpreter, but i got the error as the following
Traceback (most recent call last):
File "C:\Users\linda\workspace\LearningPyDev\main.py", line 11, in
import z3
File "C:\Users\linda\z3\python\z3.py", line 45, in
from z3printer import *
File "C:\Users\linda\z3\python\z3printer.py", line 8, in
import sys, io, z3
ImportError: No module named io
What is the io module anyway? Is it possible to run z3 in pydev?
io is a core Python module. It was added in 2.6 and has been present in every subsequent version. Are you on a very old version of Python? If you're running Python version 2.5 or earlier (you can check with python --version in any commandline), you'll need to update Python to a newer version.