Converting .py files into .exe - py2exe

I have downloaded and installed py2exe (windows). I can't run any of the modules like build_exe.py in either IDLE or in Jupyter. In IDLE the error is related to importing the file "runtime.py". In Jupyter, I can't even load the script. It says that the file is "not UTF - 8 encoded."
I have tried changing the working directory to the py2exe folder.
from . import runtime
ValueError: Attempted relative import in non-package
The script should run and create a directory named "Build"
Please help me understand this error conceptually. Is this related to the installation directory I had chosen (C:\anaconda3\site-packages instead of C:\anaconda3)

Related

Python 3.9 , DLL import error even though .py file and .pyd files are present at same location

I am running file.py in that file In file.py I am importing dll of file2 as import _file2.
file2.pyd is present in the same folder. Still I am getting dll import fail.
I have tried adding path in environment variable , os.add_dll_directly, sys.path. but nothing worked till now.
When I am running same file without any changes in python3.7 it is working fine.

no sudo cyipopt anaconda install : ImportError: libipopt.so.1: cannot open shared object file: No such file or directory

I am trying to install cyipopt package without sudo via anaconda on python 3.
I run conda install -c conda-forge cyipopt.
Then upon attempting to import cyipopt (import cyipopt) I get the error,
ImportError: libipopt.so.1: cannot open shared object file: No such file or directory
I do not know what libipopt.so.1 is. I presume it is a package ?
I found some relevant solutions, but I do not understand either of them or seem to missing some context.
In https://github.com/xuy/pyipopt the solution to my problem that is given is to find libipopt.so.1 and move it somewhere I have access to it. But I do not know where to find this package nor where an appropriate location for it is.
Meanwhile libipopt.so.1: Cannot open shared object file suggests changing/adding a path but I am not sure what paths are meant. I do not understand what is meant by the environment variable here and where I am to export it to.

Biopython, import error with "import Bio"

I have installed Biopython by Anaconda on Windows.
When I try import Bio I get this error:
ModuleNotFoundError: No module named 'Bio'
Why?
Simone.. it looks like your installation did go wrong somehow. Regardless of why and how try the following stepwise approach to see if your import error remains.
On Windows (the dots denote your installed program path specifics):
e.g. go to: C:\....\Anaconda...\Lib\site-packages
find and remove folders using delete.
folder 1: "\Bio"
folder 2: "\biopython-1.70.dist-info"
The version value 1.70 might be 1.69 when using conda for installation.
Empty your trashbin. This way the system can't do tricks and recover or link to deleted files and folders.
Install pip if its not and grab it from here.
try pip install biopython --no-cache-dir
Voila! Hope it works now for you too... Enjoy!
In case its not check windows environment variables\path.. via control panel>advanced system settings to include PATH to site-packages. Or do similar on other OS.

pyinstaller and simplehttpserver on OSX vs WIN

I've made a simple server based on another thread here on SO: Shutting down python TCPServer by custom handler
I wrapped this up into an .exe using pyinstaller like so:
pyinstaller C:\PATH TO FILE\server.py --distpath=\PATH TO FILE\ --onedir --onefile --noconsole
This works wonderfully on Windows (currently testing on Win 7 x64). I can copy this exe to any folder and get a webserver at that location. I did it this way because I am wrapping this up into a process that would be distributed with another application. The users of this application might not have python installed and they might have a browser that blocks the types of things I would like to serve during the application process.
This should also work on osx, but when I try to wrap the same python script with pyinstaller, instead of serving up the current directory, I get a server at my /Users/Username location and not the directory from where the app was run.
My process to get this to work on both Win and OSX was to begin from the python shell and run the scripts there. This works on both platforms. If I use Terminal, cd to the directory where I want to serve files, and run the python script from there, things work fine. But any attempt I make to wrap the script into something executable leads me back to the same result of serving from /Users/Username, so I'm obviously missing something fundamental of how the wrapping is working. I am assuming it has to do with shell scripting and the script being tied to the current user?
I'd like to continue to use pyinstaller for this process since it would be the same process on Windows and OSX, but I cannot seem to get the resulting app to serve files from the directory from which it is run. Any guidance on what is happening, and how to fix it through pyinstaller (or other method) would be greatly appreciated.
#tallforasmurf on the pyinstaller Github pointed out that I missed something in the pyinstaller docs that is very important:
Adapting to being "frozen"
In some apps it is necessary to learn at run-time whether the app is
running "live" (from source) or "frozen" (part of a bundle). For
example, you might have a configuration file that, when running
"live", is found based on a module's file attribute. That won't
work when the code is bundled.
When your application needs access to a data file, for example a
configuration file or an icon image file, you get the path to the file
with the following code:
import sys
import os
...
if getattr(sys, 'frozen', False):
# we are running in a |PyInstaller| bundle
basedir = sys._MEIPASS
else:
# we are running in a normal Python environment
basedir = os.path.dirname(__file__)
The PyInstaller bootloader adds the attribute frozen to the sys
module. If that attribute exists, your script has been launched by the
bootloader. When that is true, sys._MEIPASS (note the underscore in
the name) contains the path to the folder containing your script and
any other files or folders bundled with it. For one-folder mode this
is the distribution folder. For one-file mode it is the temporary
folder created by the bootloader .
When your program was not started by the bootloader, the standard
Python variable file is the full path to the script now executing,
and os.path.dirname() extracts the path to the folder that contains
it.
I was able to os.chdir(basedir) after going up a few levels past the .app bundle directory and properly serve the files in the same directory as the .app bundle.

Can't import win32crypt python module

I have the 32 bit version of python 3.4 installed. I'm trying to use the win32crypt module after installing pywin32 but I get the following error message in git CLI:
import win32crypt
ImportError: DLL load failed: The specified module could not be found.
As recommendedhere, I used dependency walker on the win32crypt.pyd file (located at C://Python34/Libsite-packages/win32 on my computer) and several dll are missing: PYTHON34.dll, PYWINTYPES34.DLL, GPSVC.DLL, IESHIMS.DLL.
Are these missing dll likely to cause the import failure? If so, how can I fix this?
A more modern solution:
pip install pypiwin32
This contains .whl files to aid in installing on Windows.
You don't need to copy/paste any dll, simply add the pywin32 module to the windows environment variable Path. Default is: "C:\Python34\Lib\site-packages\pywin32_system32".
Please note that dependency walker still shows missing dll, so maybe it is of doubtful utility in some cases.
I try to use python x64, and it work.
another solution is that you can copy 2 dll files from "C:\Python34\Lib\site-packages\pywin32_system32" and paste them where ur .py file location is,and then use the command --add-data ".*.dll;." just make sure there're no more dll files but these two in this path. this is suitable when you are using '-F' command

Resources