Ok, I am making a program using SymPy. I use sympy.Eq, sympy.solve, and sympy.Symbol. When I compile my program and I run the command (It's a User Interface) that uses sympy.solve, sympy.Eq, and sympy.Symbol. It works perfectly when it is not compiled, but when I compile it with py2exe (as a bundled executable), it gives my this error:
Traceback (most recent call last):
File "RateTime.py", line 46, in <module>
File "RateTime.py", line 33, in main
File "RateTime.py", line 4, in get_catch_up_time
File "sympy\solvers\solvers.pyc", line 883, in solve
File "sympy\solvers\solvers.pyc", line 316, in check_assumptions
File "sympy\assumptions\ask.pyc", line 88, in ask
File "sympy\assumptions\assume.pyc", line 94, in _eval_ask
File "sympy\assumptions\assume.pyc", line 157, in eval
File "sympy\utilities\source.pyc", line 26, in get_class
ImportError: No module named handlers
I tried changing the code in source.py from
lookup_view = getattr(__import__(mod_name, {}, {}, ['*']), func_name)
to
exec "import "+mod_name+" as MODULE"
lookup_view = getattr(MODULE, func_name)
And it gave me the error even when the project WASN'T compiled. I assume a python file in sympy is not being included because it is not normally imported immediatly. I had to change it back. Is there a way to fix this? I really need my python project to be distributed as a executable. Thanks!
I think that the ImportError does indeed mean that py2exe didn't pick up sympy.assumptions.handlers nor its submodules. The easiest workaround is probably to add
import sympy.assumptions.handlers.calculus
right where you import sympy.
You may need to do the same for "order", "sets" and "ntheory" in addition to "calculus".
If you don't mind changing the sympy code, I suppose you could add those files to the relevant __init__.py files, so that they are imported when sympy is.
Related
I am using the pyattck module to retrieve information from mitre att&ck.
Versions:
- pyattck==7.0.0
- pyattck-data==2.5.2
Then, I just created a simple main.py file to test the module.
from pyattck import Attck
def main():
attck = Attck()
for technique in attck.enterprise.techniques:
print(technique.name)
if __name__ == '__main__':
main()
When running the main.py script I get the following exception:
Traceback (most recent call last):
File "/<path>/main.py", line 15, in <module>
main()
File "/<path>/main.py", line 8, in main
for technique in attck.enterprise.techniques:
File "/<path_venv>/lib/python3.10/site-packages/pyattck/attck.py", line 253, in enterprise
from .enterprise import EnterpriseAttck
File "/<path_venv>/lib/python3.10/site-packages/pyattck/enterprise.py", line 7, in <module>
class EnterpriseAttck(Base):
File "/<path_venv>/lib/python3.10/site-packages/pyattck/enterprise.py", line 42, in EnterpriseAttck
__attck = MitreAttck(**Base.config.get_data("enterprise_attck_json"))
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 55, in __init__
raise te
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 53, in __init__
self.__attrs_init__(**kwargs)
File "<attrs generated init pyattck_data.attack.MitreAttck>", line 14, in __attrs_init__
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 66, in __attrs_post_init__
raise te
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 62, in __attrs_post_init__
data = TYPE_MAP.get(item['type'])(**item)
TypeError: 'NoneType' object is not callable
Anyone knows where is the issue? Maybe I have forgotten to import something? It would be helpful to know if this module actually works in another version. This one is the lasted stable one ATTOW.
UPDATE
There is am issue with this project. Mitre added some new features that are not supported by the module and make it unusable.
There is an issue on github related to this.
They have already fixed this issue in future releases. You just need to update your package pyattck-data form the bugged version 2.5.2 to 2.6.1 (or any newer).
If you are using pip, just run this:
pip install --upgrade pyattck-data
If you are using conda (inside your venv):
conda update pyattck-data
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.
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..
I have an issue when I am trying to decompile a .pyc file.
The traceback is the following:
Traceback (most recent call last):
File "my.py", line 4, in <module>
uncompyle2.uncompyle_file("/home/user/Downloads/asd.pyc", fileobj)
File "/home/user/Desktop/uncompyle2/uncompyle2/__init__.py", line 130, in uncompyle_file
uncompyle(version, co, outstream, showasm, showast, deob)
File "/home/user/Desktop/uncompyle2/uncompyle2/__init__.py", line 93, in uncompyle
tokens, customize = scanner.disassemble(co, deob=deob)
File "/home/user/Desktop/uncompyle2/uncompyle2/Scanner.py", line 214, in disassemble
cf = self.find_jump_targets(code)
File "/home/user/Desktop/uncompyle2/uncompyle2/Scanner.py", line 926, in find_jump_targets
self.detect_structure(i, op)
File "/home/user/Desktop/uncompyle2/uncompyle2/Scanner.py", line 737, in detect_structure
if int(self.code[jmp]) == RETURN_VALUE:
**TypeError: array indices must be integers**
Any ideas about this ?
I'm using Python 2.7.6 on a Ubuntu machine.
The command that I'm running to have this work is the following:
uncompyle2 asd.pyc
//EDIT: As far as I can tell, this happens only on a specific file(asd.py). It works on other files.
Any workaround ?
The .pyc file that you're trying to decompile is probably obfuscated. It's not uncompyle2s job to also deofuscate the file.
Try something else like pyc2py. Maybe it will work.
I'm trying to access the .olb files that ship with ArcGIS10.1 using the comtypes module. Some of the .olb files work (esriGeometry.olb) and some of them don't (esriSystem.olb), and some of them work some of the time (esriSearch.olb).
The following code
from comtypes.client import GetModule
olb_path = 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\com\\esriSystem.olb'
m = GetModule(path)
raises this traceback and exception
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
test3()
File "D:\Data\MatthewPlourde\JAMES\gis_tools\tool.py", line 139, in test3
m = GetModule(path)
File "C:\Python27\ArcGIS10.1\lib\site-packages\comtypes\client\_generate.py", line 112, in GetModule
mod = _CreateWrapper(tlib, pathname)
File "C:\Python27\ArcGIS10.1\lib\site-packages\comtypes\client\_generate.py", line 188, in _CreateWrapper
mod = _my_import(fullname)
File "C:\Python27\ArcGIS10.1\lib\site-packages\comtypes\client\_generate.py", line 26, in _my_import
return __import__(fullname, globals(), locals(), ['DUMMY'])
File "C:\Python27\ArcGIS10.1\lib\site-packages\comtypes\gen\_5E1F7BC3_67C5_4AEE_8EC6_C4B73AAC42ED_0_10_1.py", line 5705, in <module>
( ['in'], POINTER(_midlSAFEARRAY(POINTER(BSTR))), 'pParameters' ),
File "C:\Python27\ArcGIS10.1\lib\site-packages\comtypes\safearray.py", line 18, in _midlSAFEARRAY
sa_type = _make_safearray_type(itemtype)
File "C:\Python27\ArcGIS10.1\lib\site-packages\comtypes\safearray.py", line 53, in _make_safearray_type
raise TypeError(itemtype)
TypeError: <class 'comtypes.errorinfo.LP_BSTR'>
Apparently comtypes.safearray._make_safearray_type doesn't know what to do with <class 'comtypes.errorinfo.LP_BSTR'>. If there's anyone out there using ArcGIS10.1, I'd be grateful to know whether you can reproduce this error, and especially grateful if you know the cause.
I found a solution posted on the ArcGIS forums. It simply involves modifying automation.py in the comtypes source. Add the entry POINTER(BSTR): VT_BYREF|VT_BSTR to the _ctype_to_vartype dictionary.
After this, all the .olb's load.
I too, am having this exact error and I can't get past it. If you find out what happens please update this. The only thing I can find is something saying that there may be mixing 32 bit with 64 bit libs.
(also, I don't see where I can send a reply to your question... only an answer. I don't use stackexchange much)
Let me add something that may help you, this was taken from: http://forums.arcgis.com/threads/15848-ArcMap-10-ArcObjects-and-Python-very-cool-but-help-with-a-couple-of-problems
import logging
# grab rootlogger
_loggy = logging.getLogger()
_loggy.setLevel(logging.DEBUG)
_loggy.addHandler(logging.FileHandler("derpdebug.log"))
import os
import comtypes.client
# change com_dir to whatever it is for you
com_dir = r'C:\Program Files (x86)\ArcGIS\Desktop10.0\com'
coms = [os.path.join(com_dir, x) for x in os.listdir(com_dir) if os.path.splitext(x)[1].upper() == '.OLB']
map(comtypes.client.GetModule, coms)
# check add whatever you want here.
import comtypes.gen.esriArcMapUI
import comtypes.gen.esriGeodatabase
print dir(comtypes.gen.esriArcMapUI)
Then I just did:
grep -v ^Release derpdebug.log >readable.log