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

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.

Related

Converting .py files into .exe

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)

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

Jython 2.5 and virtualenv on windows

I have installed Jython 2.5 on Windows, then setuptools and finally virtualenv (1.8.4) using easy_install. Now I am trying to create a new virtual environment using the following command line :
jython \Lib\site-packages\virtualenv-1.8.4-py2.5.egg\virtualenv.py jython_env
But the creation of the new virtual environment fails with the following error:
os.symlink(py_executable_base, full_pth)
AttributeError: 'module' object has no attribute 'symlink'
I guess this is because Windows does not handle symlinks but does anyone already meet this issue, is there any workaround ?
Thanks
A little bit late, but for the benefit of others who may read this page...
I recently encountered the same issue with jython2.7.0 and managed to get around this by hacking jython's Lib/os.py (mine was under C:\jython2.7.0) to add at the bottom:
def symlink(target, file):
''' Just copy files in Windows,
maybe you could use mklink system calls instead '''
from shutil import copy
copy(file, target)
Don't forget to remove the compiled bytecode version of the os module otherwise the changes won't be loaded.
Then try running virtualenv -p /path/to/jython.exe jython-env-name.
Note that you should either have python2*.dll from your jython bin/ directory in your system PATH , have the dll registered or else copy the dll into your new virtualenv's bin directory.

Resources