I'm trying to use p2exe to build an exe from a python script that uses pymodbus and twisted (with lots of underlying dependencies apparently). I can build the exe but it does not run properly. I'm trying to figure out what I am doing wrong setting up the environment. I'm confident it is not my script because I can run it just fine from the python command line interpreter.
My python script uses these modules...
from pymodbus.server.async import StartTcpServer
from pymodbus.datastore import ModbusSequentialDataBlock
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext
import sys
import logging
from twisted.internet.task import LoopingCall
I get this error on python setup1.py py2exe...
The following modules appear to be missing
['Crypto.PublicKey._fastmath', 'FCNTL', 'OpenSSL', 'OpenSSL.SSL', 'OpenSSL._util', 'PAM', 'System', 'System.IO.Ports', 'TERMIOS', '_scproxy',
'gmpy', 'idna', 'pkg_resources', 'pyasn1.codec.ber', 'pyasn1.error', 'pyasn1.type', 'queue', 'resource', 'service_identity', 'service_identity
.pyopenssl', 'twisted.python._initgroups', 'twisted.python.sendmsg']
It builds the exe. When I run the exe this happens...
C:\Users\jlaird\Desktop\slush\dbclienttest\dist>modbus_slave2.exe
Traceback (most recent call last):
File "modbus_slave2.py", line 1, in <module>
File "pymodbus\server\async.pyc", line 18, in <module>
File "pymodbus\internal\ptwisted.pyc", line 5, in <module>
File "twisted\conch\manhole_ssh.pyc", line 14, in <module>
File "twisted\conch\ssh\factory.pyc", line 15, in <module>
File "twisted\conch\ssh\transport.pyc", line 32, in <module>
File "twisted\conch\ssh\keys.pyc", line 20, in <module>
ImportError: No module named pyasn1.error
If I start python and do 'import pyasn1' it imports without error. I can also import twisted and pymodbus just fine. Python can reach it but not py2exe. Why?
Figured it out...for some reason the contents of the build\lib folder for pyasn1 was not copied into C:\Python27\Lib\site-packages. Only an egg was copied. So I moved the folder over into site-packages and py2exe built an executable that worked.
Related
I use py2exe to compile python script. The python script runs without any error before compiling.
below is the setup.py
from distutils.core import setup
import py2exe, sys, os
import matplotlib
import numpy
from glob import glob
sys.argv.append('py2exe')
datafiles = [("Microsoft.VC90.CRT", glob(r'C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_99b61f5e8371c1d4\*.*'))]
datafiles.extend(matplotlib.get_py2exe_datafiles())
setup(windows=['Run.py'], data_files= datafiles, options={"py2exe": {"includes": ["matplotlib"]}})
In the run.py, I imported pandas. Pandas is used in a function as below
import pandas
def PossDist(Iterations, AssumptionFolder, ResultFolder, SampledResult):
SampledLoss = pandas.read_csv(SampledResult)
d= pandas.pivot_table(...)
The compile finished successfully without error.
When I run the compiled run.exe, I got error as below.
Traceback (most recent call last):
File "Run.py", line 6, in
File "xlwings__init__.pyc", line 34, in
File "xlwings\main.pyc", line 1727, in
File "xlwings\conversion__init__.pyc", line 3, in
File "pandas__init__.pyc", line 26, in
Main Features
File "pandas_libs__init__.pyc", line 4, in
File "pandas_libs\tslib.pyc", line 12, in
File "pandas_libs\tslib.pyc", line 10, in __load
File "pandas_libs\tslib.pyx", line 1514, in init pandas._libs.tslib
AttributeError: type object 'pandas._libs.tslib._TSObject' has no attribute 'reduce_cython'
Anyone have any clue?
Is there other way to let others run my python script on pc without python installed?
Thanks,
I want to use regex package without installation (neither using pip nor python setup.py install)
For that, I have downloaded the package and kept in the same directory of the file where I am importing regex. The code is given below
import sys
import os
currentdirectory = os.getcwd()
sys.path.append(currentdirectory+"/packages/regex/Python2/")
from regex import *
I am getting following error as _regex extension module is not created.
Traceback (most recent call last):
File "test.py", line 30, in <module>
from regex import *
File "/Users/nilakshi/test_branch/packages/regex/Python2/regex.py", line 387, in <module>
import _regex_core
File "/Users/nilakshi/test_branch/packages/regex/Python2/_regex_core.py", line 21, in <module>
import _regex
ImportError: No module named _regex
How do I create _regex extension module that can be locally used?
Also, can I create _regex extension module file such that I can use the same file in different machines without creating again?
I have a C++ program, which has an embedded python 3.4.3+. I am attempting to run a script which uses a module named requests, this module depends on socket, but the embedded interpreter in unable to import _socket
Python Version and Callstack
3.4.3+ (3.4:f4cd9ac378d7+, Feb 16 2016, 21:24:03) [MSC v.1800 32 bit (Intel)]
Traceback (most recent call last):
File "<project path>\client_example.py", line 30, in <module>
import requests
File "F:\Python 3.4.3\lib\site-packages\requests\__init__.py", line 58, in <module>
from . import utils
File "F:\Python 3.4.3\lib\site-packages\requests\utils.py", line 12, in <module>
import cgi
File "F:\Python 3.4.3\Lib\cgi.py", line 39, in <module>
from email.parser import FeedParser
File "F:\Python 3.4.3\Lib\email\parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "F:\Python 3.4.3\Lib\email\feedparser.py", line 27, in <module>
from email import message
File "F:\Python 3.4.3\Lib\email\message.py", line 16, in <module>
from email import utils
File "F:\Python 3.4.3\Lib\email\utils.py", line 29, in <module>
import socket
File "F:\Python 3.4.3\Lib\socket.py", line 49, in <module>
import _socket
ImportError: No module named '_socket'
I also know that _socket.pyd is located in DLLs in the python install location, however I don't know if it should also be in another location.
How can I make my program's embedded interpreter find the _socket module?
Have you tried opening the python terminal and load the socket library? (i.e. "import socket")
I see you are using MSVC, meaning you are using windows. To open the python terminal open a command prompt and just type python and press enter. You are now in the python terminal.
If that does not work, then there is a problem with the python installation.
Another thing, if you installed python using a proper python installer well the problem will most probably not be due to a bad install.
Best regards.
try adding the path to the module to python:
sys.path.append(path/to/module)
this should allow you to import the module.
This happened to me while debugging my c++ application in VS 2019.
Because Python is missing the debug compiled files: _d.dll _d.pyd *d_.lib
Solution:
download the source code and build your debug version
Debug Version Build
copy from .\PCbuild\amd64 to your python directory
*._d.dll ==> .\%PYTHONHOME%\
*._d.pyd ==> .\%PYTHONHOME%\DLLs
*._d.pdb ==> .\%PYTHONHOME%\DLLs
*._d.lib ==> .\%PYTHONHOME%\libs
Set environment variables %PYTHONHOME% and %PYTHONPATH%
Add the path to sys.path
PyObject* sys_path = PySys_GetObject("path");
retVal = PyList_Append(sys_path, PyUnicode_FromString("C:\\Python38_64\\DLLs"));
try debugging again ;-)
Webports has projects in the ports directory for Python and several Python modules, including NumPy. The "python" port compiles a Chrome app that runs the Python interpreter in a console window. I'd like to be able to use modules that include native code, like NumPy, in that interpreter.
Here's what I've tried:
make numpy followed by make python (in hopes that the Python build process sees that I've already built NumPy and includes it), which doesn't seem to change anything
Building the python-static package, which fails with a gigantic error message that ends with libppapi_simple_cpp.a: error: undefined reference to 'PSUserMainGet'
Copying out/build/numpy/numpy-1.8.0/numpy/ into the site-packages folder in pydata.tar in the Python app. import numpy fails with an error message telling me not to import NumPy from its source directory.
Copying out/build/numpy/numpy-1.8.0/build/lib.linux-x86_64-2.7/numpy/ (which appears to have compiled .so files in it) into the site-packages folder in pydata.tar. import numpy fails with this traceback:
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/python2.7/site-packages/numpy/__init__.py", line 153, in <module>
from . import add_newdocs
File "/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/lib/python2.7/site-packages/numpy/core/__init__.py", line 6, in <module>
from . import multiarray
ImportError: cannot import name multiarray
I'm using the PNaCL toolchain version pepper_47 inside a Docker container to build the packages, and I'm running the Python app on Chrome 47.0.2526.106 (64-bit) on Xubuntu.
The raw python port doesn't catch it, but the numpy port was designed to be used with the python-static port, which will build using the modules that have previously been built. This will then assemble a unified static library that will be linked into the .pexe for python. You shouldn't need to copy any module components by hand.
I'm trying to make an exe file using py2exe. The problem is that when I try to run created exe file, it returns that it cannot import name chardet.
Traceback (most recent call last):
File "orsr_parser.py", line 10, in <module>
File "requests\__init__.pyc", line 58, in <module>
File "requests\utils.pyc", line 26, in <module>
File "requests\compat.pyc", line 7, in <module>
ImportError: cannot import name chardet
I use requests module in one of the py files in the program.
Setup.py:
from distutils.core import setup
import py2exe
packages = ['requests']
setup(console=['my_script.py'])
Do you know where could be the problem? Is there something with setup.py file?
EDIT: There is only one answer for this problem: Stackoverflow answer, but I probably don't get it. There is no directory called requests in my project.