Name conflicting in Theano - python

I am trying to import theano in a module, but I am getting a traceback:
File "/media/tarun/6A86CA8286CA4DEF/develop/pydy/pydy/codegen/code.py", line 16, in <module>
import theano
File "/usr/local/lib/python2.7/dist-packages/theano/__init__.py", line 44, in <module>
from theano.gof import \
File "/usr/local/lib/python2.7/dist-packages/theano/gof/__init__.py", line 38, in <module>
from theano.gof.cc import \
File "/usr/local/lib/python2.7/dist-packages/theano/gof/cc.py", line 55, in <module>
StrParam(""))
File "/usr/local/lib/python2.7/dist-packages/theano/configparser.py", line 223, in AddConfigVar
root=newroot, in_c_key=in_c_key)
File "/usr/local/lib/python2.7/dist-packages/theano/configparser.py", line 227, in AddConfigVar
configparam.fullname)
AttributeError: ('This name is already taken', 'gcc.cxxflags')
It seems that there is some name conflict in some config. Can anybody please point me to the same.

This error happens because some module, probably theano.gof, is imported twice. Usually, this is because a first call to import theano.gof gets started, registering 'gcc.cxxflags' in the configuration parser a first time, but then raises ImportError, which is catched and ignored.
Then, import theano.gof gets called again, tries to register the option again, which raises the exception you get.
Is there any traceback or error message before this one, or something that would give a hint of why the first import failed?

I got similar error using when using the jupyter notebook. Restarting kernel solved the issue.

Related

When I import TPotClassifier, it gets an attributeError about numpy. Specifically np.float doesn't exist. What am I missing?

Here is the full error traceback:
Traceback (most recent call last):
File "C:\Users\david\github\beluga3\SCRATCHPAPER_6.py", line 4, in <module>
from MLModule.AI.featuretoolstpot.ml_framework import MyMLModeler
File "C:\Users\david\github\beluga3\MLModule\AI\featuretoolstpot\ml_framework.py", line 8, in <module>
from tpot import TPOTClassifier
File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\tpot\__init__.py", line 27, in <module>
from .tpot import TPOTClassifier, TPOTRegressor
File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\tpot\tpot.py", line 31, in <module>
from .base import TPOTBase
File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\tpot\base.py", line 70, in <module>
from .builtins import CombineDFs, StackingEstimator
File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\tpot\builtins\__init__.py", line 29, in <module>
from .one_hot_encoder import OneHotEncoder, auto_select_categorical_features, _transform_selected
File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\tpot\builtins\one_hot_encoder.py", line 136, in <module>
class OneHotEncoder(BaseEstimator, TransformerMixin):
File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\tpot\builtins\one_hot_encoder.py", line 216, in OneHotEncoder
def __init__(self, categorical_features='auto', dtype=np.float,
File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\__init__.py", line 284, in __getattr__
raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'float'. Did you mean: 'cfloat'?
As you can see, when it tries to instantiate the class OneHotEncoder, the class has one input parameter of dtype, and it uses np.float. But apparently numpy has no such attribute. I checked all my dependencies, and made sure everything was upgrade.
I'm running Python 3.10.2
Any help would be great.
This issue happens when using tpot with numpy 1.24. This version of numpy has removed type aliases, like np.float. This was already declared as deprecated since version 1.20, and now it has been removed.
The developers of tpot should modify their code to avoid this issue. But, as a solution for the time being you can avoid the issue by simply using a version of numpy <1.24
More info on this issue and how to fix this in your own code can be found here.

Python weird ModuleNotFoundError at wrong position in code

I am having a super weird error, the situation is the following:
I am writing some code in a package called hsltools. The Module is called em_combiner1_4. I recently changed the version from 1_3, and also changed all imports accordingly.
If I run my code now, I get the following error:
Traceback (most recent call last):
File "C:\Users\...\git_home\hsltools\hsltools\tests\emc_tester\EMC_tester.py", line 85, in <module>
combine_2d()
File "C:\Users\...\git_home\hsltools\hsltools\tests\emc_tester\EMC_tester.py", line 48, in combine_2d
elec_field2d = emc.EM(import_path+"2DelecMap.ef2.npz")
File "c:\users\...\git_home\hsltools\hsltools\em_combiner1_4.py", line 441, in __init__
load_npz()
File "c:\users\...\git_home\hsltools\hsltools\em_combiner1_4.py", line 251, in load_npz
self.em_type = data["metadata"][1]
File "C:\Users\...\Anaconda3\lib\site-packages\numpy\lib\npyio.py", line 254, in __getitem__
return format.read_array(bytes,
File "C:\Users\...\Anaconda3\lib\site-packages\numpy\lib\format.py", line 744, in read_array
array = pickle.load(fp, **pickle_kwargs)
ModuleNotFoundError: No module named 'hsltools.em_combiner1_3
The thing I don't get is the location of the error: ...\numpy\lib\format.py.
There is absolutaly no import there, and anyway, numpy would not import my module.
I am wondering if I am generally misunderstanding some basic concept, or if the error is wrong.
It's happening while deserializing pickled objects. Pickle stores the type information including the module name. When loading a pickled object, the module is imported to construct the final object.
Your pickle file contains an object that is part of hsltools.em_combiner1_3. So that is the module pickle tries to find.

Python3 error when running a pandas simple program

I'm trying to run a python program that uses the pandas library on Mac OS, and I get the next error
adan_vazquez#EPAM-C02G513RML7L automate_python % python3 test_pandas.py
Traceback (most recent call last):
File "/Users/adan_vazquez/Desktop/automate_python/test_pandas.py", line 1, in <module>
import pandas as pd
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/__init__.py", line 11, in <module>
__import__(dependency)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/__init__.py", line 155, in <module>
from . import random
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/random/__init__.py", line 180, in <module>
from . import _pickle
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/random/_pickle.py", line 1, in <module>
from .mtrand import RandomState
File "mtrand.pyx", line 1, in init numpy.random.mtrand
File "bit_generator.pyx", line 40, in init numpy.random.bit_generator
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/secrets.py", line 19, in <module>
from random import SystemRandom
File "/Users/adan_vazquez/Desktop/automate_python/random.py", line 3, in <module>
print(random.randint(1,10))
AttributeError: partially initialized module 'random' has no attribute 'randint' (most likely due to a circular import)
Here's the code that I'm trying to run:
import pandas as pd
simpsons = pd.read_html('https://en.wikipedia.org/wiki/List_of_The_Simpsons_episodes_(seasons_1%E2%80%9320)')
print(len(simpsons))
print("Hola")
As you can see is not a big code and I'm getting the error, I already updated my pip3 and my python3 versions, also I reinstall pandas and I keep getting the error, if I try to import pandas in the python terminal I get the same error and I don't know what's causing it, I hope you can help me, thanks in advance.
The error message says it is a circular import error.
Try renaming /Users/adan_vazquez/Desktop/automate_python/random.py with something other than random
According to the error, it is a circular import which is causing the problem.
Since I do not have the details of your project structure or file name, my best guess is that you accidentally named your working file the same as the module name and those modules depend on each other.

Python Script Fails

I am a complete novice at Python and I wish to run a script someone has made up to check against a critical windows vulnerability. I downloaded python and I thought I had downloaded all the modules and everything needed to run this script, but I keep getting an error: Please see below
C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages>zerologon.py Dc_Name IP_address ( I put this here but I edited it for confidentiality)
Traceback (most recent call last):
File "C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\zerologon.py", line 3, in <module>
from impacket.dcerpc.v5 import nrpc, epm
File "C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\impacket\dcerpc\v5\nrpc.py", line 30, in <module>
from impacket.dcerpc.v5.samr import OLD_LARGE_INTEGER
File "C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\impacket\dcerpc\v5\samr.py", line 29, in <module>
from impacket.dcerpc.v5.rpcrt import DCERPCException
File "C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\impacket\dcerpc\v5\rpcrt.py", line 24, in <module>
from Cryptodome.Cipher import ARC4
File "C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\Cryptodome\Cipher\__init__.py", line 27, in <module>
from Cryptodome.Cipher._mode_ecb import _create_ecb_cipher
File "C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\Cryptodome\Cipher\_mode_ecb.py", line 35, in <module>
raw_ecb_lib = load_pycryptodome_raw_lib("Cryptodome.Cipher._raw_ecb", """
File "C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\Cryptodome\Util\_raw_api.py", line 308, in load_pycryptodome_raw_lib
raise OSError("Cannot load native module '%s': %s" % (name, ", ".join(attempts)))
OSError: Cannot load native module 'Cryptodome.Cipher._raw_ecb': Trying '_raw_ecb.cp38-win_amd64.pyd': cannot load library 'C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\Cryptodome\Util\..\Cipher\_raw_ecb.cp38-win_amd64.pyd': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'C:\\Users\\bhanney\\AppData\\Local\\Programs\\Python\\Python38-32\\Lib\\site-packages\\Cryptodome\\Util\\..\\Cipher\\_raw_ecb.cp38-win_amd64.pyd', Trying '_raw_ecb.pyd': cannot load library 'C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\Cryptodome\Util\..\Cipher\_raw_ecb.pyd': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'C:\\Users\\bhanney\\AppData\\Local\\Programs\\Python\\Python38-32\\Lib\\site-packages\\Cryptodome\\Util\\..\\Cipher\\_raw_ecb.pyd'
Here is a link to the github script: https://github.com/SecuraBV/CVE-2020-1472 , let me know if anyone can assist because I have no clue what I'm doing wrong
Since you said you're a novice at Python, I'll try to help you.. but you should definetely take a look at the links provided in the first comment.
So, after the formalities, let's read your error message together..
C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages>zerologon.py Dc_Name IP_address
the error was caused by this command: zerologon.py Dc_Name IP_address
Traceback (most recent call last):
traceback will show the error at the top and their dependencies...
File "C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\zerologon.py", line 3, in <module>
from impacket.dcerpc.v5 import nrpc, epm
the first line is located in your script, the zerologon.py, at line 3, where you try to run the following command: from impacket.dcerpc.v5 import nrpc, epm
File "C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\impacket\dcerpc\v5\nrpc.py", line 30, in <module>
from impacket.dcerpc.v5.samr import OLD_LARGE_INTEGER
File "C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\impacket\dcerpc\v5\samr.py", line 29, in <module>
from impacket.dcerpc.v5.rpcrt import DCERPCException
File "C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\impacket\dcerpc\v5\rpcrt.py", line 24, in <module>
from Cryptodome.Cipher import ARC4
File "C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\Cryptodome\Cipher\__init__.py", line 27, in <module>
from Cryptodome.Cipher._mode_ecb import _create_ecb_cipher
File "C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\Cryptodome\Cipher\_mode_ecb.py", line 35, in <module>
raw_ecb_lib = load_pycryptodome_raw_lib("Cryptodome.Cipher._raw_ecb", "")
File "C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\Cryptodome\Util\_raw_api.py", line 308, in load_pycryptodome_raw_lib
raise OSError("Cannot load native module '%s': %s" % (name, ", ".join(attempts)))
and here, in the last "File Error Message", we can see the root of your problem: the file \Python\Python38-32\Lib\site-packages\Cryptodome\Util\_raw_api.py, in line 308, tried to run the command: load_pycryptodome_raw_lib, but it generated an OSError...
OSError: Cannot load native module 'Cryptodome.Cipher._raw_ecb':
here we can see the OSError message: Cannot load native module 'Cryptodome.Cipher._raw_ecb', and the following part shows us the unsuccessful alternative attempts..
Trying '_raw_ecb.cp38-win_amd64.pyd':
cannot load library 'C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\Cryptodome\Util\..\Cipher\_raw_ecb.cp38-win_amd64.pyd': error 0x7e.
Additionally, ctypes.util.find_library() did not manage to locate a library called 'C:\\Users\\bhanney\\AppData\\Local\\Programs\\Python\\Python38-32\\Lib\\site-packages\\Cryptodome\\Util\\..\\Cipher\\_raw_ecb.cp38-win_amd64.pyd',
Trying '_raw_ecb.pyd': cannot load library 'C:\Users\bhanney\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\Cryptodome\Util\..\Cipher\_raw_ecb.pyd': error 0x7e.
Additionally, ctypes.util.find_library() did not manage to locate a library called 'C:\\Users\\bhanney\\AppData\\Local\\Programs\\Python\\Python38-32\\Lib\\site-packages\\Cryptodome\\Util\\..\\Cipher\\_raw_ecb.pyd'
Ok, so after executing this reading and understanding routine, we can try to find a solution to your problem, by looking at:
Cryptodome Docs
Cryptodome Github Issues
After doing this, you can even specify your search using the raw_ecb text, for example... which leads us to this page, that may be very useful for you:
ISSUES filtered by "_raw_ecb.pyd"
Or this one:
Error loading native modules #185
In this issue, the OP said the following:
"I solved it by installing the VC++ 2008 Redistributable as I could see
in dependencywalker that MSVCR90 was not found"
I know this doesn't clearly answer your question, but it may help you understand how you can fix your code in a more general way..

Python module import difference "string.maketrans"

I have come across a strange python module import issue.
When I trying to import the boilerpipe module,
from boilerpipe.extract import Extractor
I got this exception:
Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/boilerpipe-1.2.0-py2.7.egg/boilerpipe/extract/ __init__.py", line 2, in <module>
import urllib2
File "/usr/lib/python2.7/urllib2.py", line 94, in <module>
import httplib
File "/usr/lib/python2.7/httplib.py", line 1140, in <module>
import ssl
File "/usr/lib/python2.7/ssl.py", line 58, in <module>
import textwrap
File "/usr/lib/python2.7/textwrap.py", line 40, in <module>
class TextWrapper:
File "/usr/lib/python2.7/textwrap.py", line 82, in TextWrapper
whitespace_trans = string.maketrans(_whitespace, ' ' * len(_whitespace))
AttributeError: 'module' object has no attribute 'maketrans'
I've searched over internet and saying that in Python 2.6 the 'str' module has been renamed to 'string' module. So this looks like some where in code library it didn't import "string" module properly.
Yet the really strange thing is, when I run the python code from home directory and run the same piece of code (either by using python shell or using python pyfile.py), it works fine! No more import error.
So I'm bit confusing. Can anyone give me any hint?
Thanks!
Some other script in sys.path is called "string.py" and is masking the stdlib module.
Double check to make sure that you don't have a file string.py that has been imported.
To debug this, put somewhere:
import sys
raise Exception("string module: %r" %(sys.modules.get("string"), ))
That will tell you what string module was imported (or if it shows None, no string module has been imported yet).

Categories