cx_freeze and cryptodome error after compilation - python

This error appears after compiling my Python 2.7 project with cx_freeze : https://imgur.com/a/sNvYtEO
I have the impression that the error comes from the package pycryptodome / pycryptodomex which is well installed since everything works before compiling with cx_freeze.
I tried to modify the import with :
from Crypto.Cipher import AES
Instead of :
from Cryptodome.Cipher import AES
But there is always the same error..
Here are my build options on cx_freeze :
build_options = {
'packages': ['jinja2.ext'],
'namespace_packages':['zope'],
'includes': ['zope.interface', 'M2Crypto'],
'excludes': ['Tkinter']
}
I will be happy to try other solutions if you have ideas, thanks !

Try to modify the import (in your main script or importing module) as
import cffi
import _cffi_backend
from Cryptodome.Cipher import AES
If this does not work, try to add 'cffi' and '_cffi_backend' to the includes list in your setup script.
If this still does not work, see the cffi documentation and this resource for further suggestions.

Related

Error importing c module compiled with Cython into python module on Mac

I have a Cython module compiled from pyx files to c files that I am trying to import and use in a python module. I'm running python 3.6 on a Mac. When I run gcc -v the output is:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr - -with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1 Apple LLVM version 10.0.1 (clang-1001.0.46.4) Target: x86_64-apple-darwin18.7.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Running python setup.py build and python setup.py install gives no errors, and the .so and .c files for the corresponding files appear in the right directory, which is on the path.
When I try to import the module, I get an error in the init file, from a line that tries to import another submodule:
from . import subModule
I've tried updating python and Cython, and I've made sure that gcc is in user/lib.
This is my setup.py file:
from Cython.Build import cythonize
setupArgs = dict(
name="module",
version="1.1.0",
description=description,
url="https://github.com/XXXX/XXXXX/module",
author="CTcue",
author_email="info#XXXXXX.com",
ext_modules=cythonize(["module/*.pyx"]),
)
# Use distutils setup
from distutils.core import setup
setup(**setupArgs)
This is the error message:
File "module/subModule.pyx", line 4, in init module.subModule
ModuleNotFoundError: No module named 'thirdModule'
The thirdModule in question has a .c file and a .so file that correspond to the .pyx file, and as far as I can tell everything is order there.
module's init.py:
__title__ = 'Pseudonomizer'
__version__ = '1.0.2'
__author__ = 'CTcue'
__license__ = 'Proprietary'
__copyright__ = 'Copyright 2016 CTcue'
from . import subModule
subModule:
import thirdModule
thirdModule.doSomething()
third module:
import re
from . import anotherModule
def doSomething:
#code that does something
Edit : In an attempt to see if the compiler is at fault, I tried to manually compile the .c file of thirdModule with "gcc thirdModule", and got the following error:
Undefined symbols for architecture x86_64:
This seems to suggest that the issue is compiler-related, but I still haven't found the solution.
Any help would be much appreciated.
It turns out #ead was right, and the problem was that the module had implicit relative imports which are no longer allowed in python 3.

Import error when building .py file to .exe

I am using python 2.7.10, and have scripted a program which plays music with the help of mp3play module. I have installed the mp3play module and the program is working fine in .py format but when I am trying to build it into .exe with the help of py2exe, It is giving me ImportError: Stating mp3play module is not installed. Here is the following code for the setup.py file for the building of exe
import os
import sys
from distutils.core import setup
import py2exe
py2exe.build_exe._py_suffixes = ['.py', '.pyo', '.pyc', '.pyw', '.dat', '.log', '.txt', '.png']
setup(
version = "1.0",
name = "abcd",
author = "pqrs,mnop",
author_email = "abcd#gmail.com,pqrs#gmail.com",
windows=[{'script': "main.py","icon_resources": [(0, "data/icon.ico")]}] , options={'py2exe':{"skip_archive": True,"unbuffered": True,'packages':['Tkinter','PIL','mp3play','tkFileDialog','tkMessageBox','ttk','os', 'sys']}}
)
can someone help me out and tell me where I am getting it wrong ??
A very elegant way of using mp3play can be refered from here http://mp3play.googlecode.com

py2exe executes file but doesn't attempt to build

My question is rather simple: if I try to build my .exe using:
python setup.py py2exe
Python just executes my main file, starting my application, however py2exe doesn't try to build it. Meaning: it does the same as if I'd do:
python setup.py
I guess something is wrong with the distutil?
Anybody already encountered this problem?
py2exe is installed (I reinstalled it, hoping it'd fix it).
My Code:
from testmain import *
from Initfile import *
import math
import py2exe
import matplotlib
import PyQt4
import numpy
from distutils.core import setup
setup(
windows=['Initfile.py'],
data_files=[("GUI", ["testmain.ui"]),*matplotlib.get_py2exe_datafiles()],
options = {
'py2exe': {
'includes' : ['math','py2exe','numpy','matplotlib','PyQt4']
}
}
)
Well the error isn't within distutil, it seems when one imports the entry point itself (in my case Initfile.py) pyexe isnt executing.
So the solution is: remove the line from Initfile import *

Compiling Pysnmp with Py2exe

I've created a program that pulls information from routers using SNMP (via PySNMP module). The application works great and I now what to compile it into a standalone application so that I can distribute it to my co-workers. However, after trying both Py2exe and PyInstaller, I've been unsuccessful in compiling a working application. I have searched the internet (a lot!) trying to find an example of someone who has successfully been able to compile their PySNMP application, but haven't been able to find anyway. Is there a better way to compile this or am I just doing it wrong?
These are the modules I've imported:
from Tkinter import *
import tkMessageBox
from pysnmp.entity.rfc3413.oneliner import cmdgen
This is the setup.py I've created for Py2exe:
from distutils.core import setup
import py2exe
setup( console = [
{ "script": "RSSIChecker.py",
}],
options = {
"py2exe":{
'includes': [
'pysnmp.smi.mibs.*',
'pysnmp.smi.mibs.instances.*'
]
}
}
)
Any suggestions?
With the following setup.py, a pysnmp-based app can be packaged with py2exe right out of the box (see line 101 and below). There are also some additional modules added implicitly into py2exe packaging as they are used by the app, not pysnmp itself.

py2exe `ImportError: No module named backend_tkagg`

I am trying to make a windows executable from a python script that uses matplotlib and it seems that I am getting a common error.
File "run.py", line 29, in
import matplotlib.pyplot as plt File "matplotlib\pyplot.pyc", line 95, in File "matplotlib\backends__init__.pyc", line
25, in pylab_setup ImportError: No module named backend_tkagg
The problem is that I didn't found a solution while googling all over the internet.
Here is my setup.py
from distutils.core import setup
import matplotlib
import py2exe
matplotlib.use('TkAgg')
setup(data_files=matplotlib.get_py2exe_datafiles(),console=['run.py'])
First, the easy question, is that backend installed? On my Fedora system I had to install it separately from the base matplotlib.
At a Python console can you:
>>> import matplotlib.backends.backend_tkagg
If that works, then force py2exe to include it. In your config:
opts = {
'py2exe': { "includes" : ["matplotlib.backends.backend_tkagg"] }
}
If you are using py2exe it doesn't handle .egg formatted Python modules. If you used easy_install to install the trouble module then you might only have the .egg version. See the py2exe site for more info on how to fix it.
http://www.py2exe.org/index.cgi/ExeWithEggs
This works well
from distutils.core import setup
import py2exe, sys, os
import matplotlib
sys.setrecursionlimit(12000)
sys.argv.append('py2exe')
setup(
options = {
"py2exe" : {
"bundle_files":3,
"compressed":True,
"includes" : ["matplotlib.backends.backend_tkagg"]
}
},
windows = [{"script": "script.py"}],
zipfile = None,
data_files=matplotlib data_files = matplotlib.get_py2exe_datafiles(),
)
Run the following command to install the backend_tkagg
For centos -- sudo yum install python-matplotlib-tk
This should work.

Categories