DLL load failed: The specified procedure could not be found [duplicate] - python

I created python executables with py2exe with both 64bit python interpreter and 32 bit python interpreter.
In my program, I use the module pywin32 com, and so I dl'ed and installed both the 64bit and 32bit versions of the program prior to creating the executable.
The 64bit exe works fine, but the 32 bit one has the following problem:
Traceback (most recent call last):
File "program.py", line 11, in <module>
File "win32com\__init__.pyc", line 5, in <module>
File "win32api.pyc", line 12, in <module>
File "win32api.pyc", line 10, in __load
ImportError: DLL load failed: The specified procedure could not be found.
I tried both versions by running the source directly, ie python program.py and C:\python_32\python.exe program.py and both work fine.
Note I tested the 64bit exe on a 64bit windows 7 computer and the 32bit exe on a 32bit windows XP computer.

Older than everything ever, but I stumbled on this problem today, and if anyone else does, what I ran was:
python /c/Python26/Scripts/pywin32_postinstall.py -install from the commandline (change values to fit). That worked:
$ python /c/Python26/Scripts/pywin32_postinstall.py -install
Copied pythoncom26.dll to C:\WINDOWS\system32\pythoncom26.dll
Copied pythoncomloader26.dll to C:\WINDOWS\system32\pythoncomloader26.dll
Copied pywintypes26.dll to C:\WINDOWS\system32\pywintypes26.dll
Registered: Python.Interpreter
Registered: Python.Dictionary
Registered: Python
-> Software\Python\PythonCore\2.6\Help[None]=None
-> Software\Python\PythonCore\2.6\Help\PythonwinReference[None]='c:\\Python26\\Lib\\site-packages\\PyWin32.chm'
Pythonwin has been registered in context menu
Creating directory c:\Python26\Lib\site-packages\win32com\gen_py
Shortcut for Pythonwin created
Shortcut to documentation created
The pywin32 extensions were successfully installed.`
(On WinXP SP3)

Had the above noted errors with my python27 pywin32 installation that got installed after my installation of ArcGIS on a windows2008 R2 server (trying to centralize our scripts).
Found that for me, I had to start a command line window with run as adminstrator (right click to get that option in windows) and then run the following command line from the c:\arcpy27\arcgis10.1>python c:/arcpy27/arcgis10.1/scripts/pywin32_postinstall.py -install
I see a lot of people have run into this issue and I tried multiple things, but this was finally the solution that managed to get pywin32 installed.
Thanks so much for your solution. Took me a couple of install and uninstalls before I finally ran across your solution and modified it for my version.

Related

AttributeError: module 'os' has no attribute 'fork' while using Ubuntu Bash from Windows Linux Subsystem

There's some code I'd like to use from GitHub on my Windows 10 machine. The error I keep getting is:
AttributeError: module 'os' has no attribute 'fork'
I looked this up and found that Windows doesn't support the os.fork() call, so I tried looking into ways to get bash on a Windows machine (I might need bash for other scripts in the future). I discovered the Windows Linux Subsystem, and it sounded exactly right for this. I installed WLS1 and got Ubuntu for it from the Microsoft store. Bash seems to work as expected, but this script still throws the same error in bash.
I've found a similar question from a few years ago (how to run python script with os.fork on windows?). The accepted answer recommended running a Linux application on a virtual machine, which I think is exactly what I'm doing (right?). Does anyone know how I can get this script to work? (Btw I know it works bc I've run it before on my Linux machine at work.)
Edit: This might be a symptom of another problem.
I think this means Ubuntu WSL1 is using the Linux path to python:
In Powershell: Get-Command python gives me C:\Users\myname\AppData\Local\Microsoft...
In Ubuntu: which python gives me /usr/bin/python3
..
In Powershell, if I try to read the .toml file using wellmap .\wellmap-text.toml, I get the "not in Path" error (which I've been seeing for a lot of things, as I try to set up my machine, and I'm unfamiliar with the right way of adding things to my Path or if doing so could break something)
wellmap : The term 'wellmap' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ wellmap .\wellmap-text.toml
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (wellmap:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
On the Ubuntu WSL, running wellmap ./wellmap-text.toml gives me a command not found error.
..
Because I know the Path to the wellmap.exe, I tried to give Powershell and Ubuntu that Path directly and be super explicit. This is where I get the module 'os' has no attribute 'fork' error.
In Powershell:
& “C:\Users\myname\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts\wellmap.exe” \Users\myname\Desktop\wellmap-text.toml
And this error:
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "C:\Users\myname\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts\wellmap.exe_main.py", line 7, in
File "C:\Users\myname\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\wellmap\plot.py", line 101, in main
if os.fork() != 0:
AttributeError: module 'os' has no attribute 'fork'
In Ubuntu:
/mnt/c/Users/myname/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/local-packages/Python39/Scripts/wellmap.exe /mnt/c/Users/myname/Desktop/wellmap-test.toml
And the same error too:
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\runpy.py", lin
e 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\runpy.py", lin
e 87, in run_code
exec(code, run_globals)
File "C:\Users\myname\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-package
s\Python39\Scripts\wellmap.exe_main.py", line 7, in
File "C:\Users\myname\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-package
s\Python39\site-packages\wellmap\plot.py", line 101, in main
if os.fork() != 0:
AttributeError: module 'os' has no attribute 'fork'
You may want to specify the script, the Linux distribution on the WSL (and version). Just tried it on Ubuntu 20.04 on WSL2 with Python 3.8.5. The following lines
import os
os.fork()
work fine.
The information you've added to the updated question highlights a likely problem. You say that in Ubuntu, you are running:
/mnt/c/Users/myname/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/local-packages/Python39/Scripts/wellmap.exe /mnt/c/Users/myname/Desktop/wellmap-test.toml
If that's, the case, then you are still running the Windows version of wellmap.exe under Ubuntu. Because it's running the exe, WSL passes control back to Windows (it's a bit more complicated than this). Regardless, if you are running the .exe, then it's running in the Windows Python environment, not under Linux Python.
Let's try actually installing and running the Linux Python wellmap. We can do this in a virtual environment, to prevent changing the default Python environment. In Ubuntu:
cd ~ # Or whever you want to set up this virtual environment
python -m venv wellmap-venv # since we've already confirmed that this points to the Linux version
. wellmap-venv/bin/activate
pip install wellmap
And then try wellmap (without an extension) with your .toml file. That .toml file can still be in a Windows path without impact.
Since you mentioned that you tried running this on Python on Windows first, it's likely that your Windows Python version is still taking priority over your Linux Python.
Check the Python location with which python3. You'll probably find it pointing to the Windows version.
Check your path in Ubuntu. You'll probably find that the Windows Python version is there, and it has precedence over the Linux version. This is because WSL "helpfully" prepends the Windows path to the Linux path to allow you to access your Windows apps and utilities under Linux. This is useful in most cases, but can cause problems when both the Windows and Linux version of a tool are installed.
Assuming that is the case, there are quite a few workarounds that I know of. Three of them, you can read about in my answer here regarding a similar problem with npm on WSL. They are all applicable to Python just as much as nodejs/npm.
Of course, you can also just specify the full path to the Linux Python, /usr/bin/python3, when launching your app.

Pycharm: DLL load failed: The specified procedure could not be found

I am working on a Python project in Pycharm (2020.1.2) on Windows 10.
For this project, I cannot use the standard Python interpreter, I have to use my own located at C:\some\path\here\python\27_64\python.exe (Python 2.7.3).
Backstory may be important:
I have added this path to the system path for both myself and all users, and placed it ahead of %LOCALAPPDATA%\Microsoft\WindowsApps to try to prevent the Microsoft store from popping up whenever I try to run python on the command line - however I don't feel like this change to the path variable has made a difference, as the Microsoft store still pops up.
I can start a Python shell by running C:\some\path\here\python\27_64\python.exe, so I know it technically works. When I do so; the sys.path is as follows:
['', 'C:\\another_place\\Python_2.7.3_x64\\python27.zip',
'C:\\some\\path\\here\\python\\27_64\\DLLs',
'C:\\some\\path\\here\\python\\27_64\\lib',
'C:\\some\\path\\here\\python\\27_64\\lib\\plat-win',
'C:\\some\\path\\here\\python\\27_64\\lib\\lib-tk',
'C:\\some\\path\\here\\python\\27_64',
'C:\\some\\path\\here\\python\\27_64\\lib\\site-packages']
Anyway, when I try to run a Python console (not even my script), this is the message I get in Pycharm:
C:\some\path\here\python\27_64\python.exe "C:\Program Files\JetBrains\PyCharm 2020.1.1\plugins\python\helpers\pydev\pydevconsole.py" --mode=client --port=59771
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2020.1.1\plugins\python\helpers\pydev\pydevconsole.py", line 5, in <module>
from _pydev_comm.pydev_rpc import make_rpc_client, start_rpc_server, start_rpc_server_and_make_client
File "C:\Program Files\JetBrains\PyCharm 2020.1.1\plugins\python\helpers\pydev\_pydev_comm\pydev_rpc.py", line 1, in <module>
import socket
File "C:\some\path\here\python\27_64\lib\socket.py", line 47, in <module>
import _socket
ImportError: DLL load failed: The specified procedure could not be found.
Process finished with exit code 1
I have gone to Settings>Project:[name]>Project Interpreter and set it to C:\some\path\here\python\27_64\python.exe (and rebooted Pycharm to be sure). That said; in the settings window no packages are shown and it claims that Python packaging tools can not be found.
When I click the link to install them (circled in red), they can not be installed due to this error:
ImportError: cannot import name _remove_dead_weakref
Are there other variables or settings I need to change?
Thanks
EDIT
Uninstalling the first Python on my Path (C:\\another_place\\Python_2.7.3_x64\\python27.zip) just makes everything so much worse
EDIT 2
I added the PATH variable manually to both the Python console settings and to the Run/Debug settings in PyCharm (and restarted the program), the result is still the same
I had a similar issue. This procedure fixed my issue.
Try the following:
run print(os.environ['PATH']) in the system terminal using the same interpreter
copy the result and add as PATH environment variable to your Run/Debug Configuration
do the same for Python Console settings
I hope it will work.
It seems that the interpreter is not being recognized by the windows as a result of which you are unable to install packages.
Also, I suppose the interpreter should be present in the bin folder of your python folder. The interpreter does not have a .exe extension.
I would suggest installing anaconda python 2.7 64 Bit windows package installer and using the condo environment and work on python 2.7
Here is a link I found for Python 2.7 on Windows hope this helps:
https://docs.python.org/2/faq/windows.html
Had the similar issue, in my case it was always trying to find libraries in PostgreSQL installation directory.
Mentioning sys.path helped me here! I tried printing it from inside my script and realized that PostgreSQL directories appear earlier in the list than Python directories.
SO, how I finally fixed it -- added PYTHONPATH environment variable to my Run configuration in PyCharm like this (replace with paths to your Python installation directory):
PYTHONPATH=D:\PROGRAMS\Python\Python3.9\DLLs\;D:\PROGRAMS\Python\Python3.9\lib\;D:\PROGRAMS\Python\Python3.9\;D:\PROGRAMS\Python\Python3.9\lib\site-packages
This helps to put desired directories at the beginning of the list, thus they are searched first and required libraries are found as it is supposed to work.

Python SSL Import Error in PyInstaller generated executable

I'm trying to distribute an executable file of a Python program I've created.
For this purpose I'm using PyInstaller .
I use Windows 7 Professional with Python 3.7
The program runs successfully when inside PyCharm and produces the expected results.
As described in the PyInstaller manuals I've created the dist folder with:
pyinstaller main.py
The log output specifies that the process finished successfully.
When trying to run the main.exe from the distribution folder, the below error is produced:
Traceback (most recent call last):
File "site-packages\PyInstaller\loader\rthooks\pyi_rth_certifi.py", line 11, i
n <module>
File "c:\users\tim\anaconda3\envs\timtf2_37\lib\site-packages\PyInstaller\load
er\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "ssl.py", line 98, in <module>
ImportError: DLL load failed: The specified procedure could not be found.
[6236] Failed to execute script pyi_rth_certifi
So after a couple of hours, I managed to solve the problem.
I did several things and still unsure what was the actuall fix, but this is the step-by-step flow I've done:
Created a new environment using Anaconda. I've downgraded the Python version to 3.6.8, since I saw mentions of several compatibility problems with Python 3.7
Installed all the requirements from my project, using Anaconda, since some mention problems due to mixed usage of pip and conda.
Installed the latest version of pyinstaller.
Activated the new environment and run pyinstaller from within it on the main.py script of the program with --hidden-import pyodbc argument.
That's it, now the distibuted program works on all Windows computers in the office.

IntelliSense not working with Visual Studio Code/embeddable python

I want to use the embeddable version of python (3.7.0) in an windows 10 environment without need of an installer/admin permissions. Visual Studio Code is the IDE to be configured with the python interpreter above.
To install embeddable python, I followed the instructions of this answer and this issue and it works fine on CLI.
Setup VS Code according to this site:
installed Python extension and linter
added my python folder (root of python.exe) and subfolder \Scripts in PATH environment: C:/my/path/to/Python,C:/my/path/to/Python/Scripts
configured the interpreter like this in user settings: python.pythonPath": "C:/my/path/to/Python/python.exe
Sample script:
msg = "Hello World"
print(msg)
In VS Code I CAN execute the script by right click on active editor -> "Run Python file in terminal".
But I get no IntelliSense:
When I print the sys.path, it gives me
C:\my\path\to\Python\python37.zip
C:\my\path\to\Python\
C:\my\path\to\Python\lib\site-packages
Documentation for Python extension says nothing about embeddable python not been supported:
Install a version of Python 3 (for which this tutorial is written).
Options include:
(All operating systems) A download from python.org; typically use the
Download Python 3.6.5 button that appears first on the page (or
whatever is the latest version).
...
Any ideas how to solve this?
I was using the Python version from Anaconda but I was also not able to get Intellisense to display anything, similar to what you're describing.
In the end, the way that I got Python intellisense to start working in VS Code was to:
open up the Terminal (View menu => Terminal)
type conda init powershell
restart VS Code
After that, Python intellisense started working correctly.
I had the same issue of IntelliSense not working - nothing displayed and "Loading..." when actively asking for an autocomplete using ctrl + space.
I was on VSCode 1.25.1, an embeddable python 3.8.6, and the Python Extension 2018.7.1
In short, python 3.8 was not supported by the Python Extension 2018.7.1
While IntelliSense failed silently on VSCode, opening Help > Toggle Developer Tools > Console, I had this error:
Python Extension: stderr jediProxy, Error (stderr) Traceback (most recent call last):
File "d:\Users\user\.vscode\extensions\ms-python.python-2018.7.1\pythonFiles\parso\grammar.py", line 236, in load_grammar
return _loaded_grammars[path]
KeyError: 'd:\\Users\\user\\.vscode\\extensions\\ms-python.python-2018.7.1\\pythonFiles\\parso\\python\\grammar38.txt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\Users\user\.vscode\extensions\ms-python.python-2018.7.1\pythonFiles\parso\grammar.py", line 239, in load_grammar
with open(path) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'd:\\Users\\user\\.vscode\\extensions\\ms-python.python-2018.7.1\\pythonFiles\\parso\\python\\grammar38.txt'
Making a grammar38.txt copy of grammar37.txt is enough to fix IntelliSense in this case - to an extent. If possible, downgrading python or upgrading vscode would be better.

dll load errors in python executable made from pywin32

I created python executables with py2exe with both 64bit python interpreter and 32 bit python interpreter.
In my program, I use the module pywin32 com, and so I dl'ed and installed both the 64bit and 32bit versions of the program prior to creating the executable.
The 64bit exe works fine, but the 32 bit one has the following problem:
Traceback (most recent call last):
File "program.py", line 11, in <module>
File "win32com\__init__.pyc", line 5, in <module>
File "win32api.pyc", line 12, in <module>
File "win32api.pyc", line 10, in __load
ImportError: DLL load failed: The specified procedure could not be found.
I tried both versions by running the source directly, ie python program.py and C:\python_32\python.exe program.py and both work fine.
Note I tested the 64bit exe on a 64bit windows 7 computer and the 32bit exe on a 32bit windows XP computer.
Older than everything ever, but I stumbled on this problem today, and if anyone else does, what I ran was:
python /c/Python26/Scripts/pywin32_postinstall.py -install from the commandline (change values to fit). That worked:
$ python /c/Python26/Scripts/pywin32_postinstall.py -install
Copied pythoncom26.dll to C:\WINDOWS\system32\pythoncom26.dll
Copied pythoncomloader26.dll to C:\WINDOWS\system32\pythoncomloader26.dll
Copied pywintypes26.dll to C:\WINDOWS\system32\pywintypes26.dll
Registered: Python.Interpreter
Registered: Python.Dictionary
Registered: Python
-> Software\Python\PythonCore\2.6\Help[None]=None
-> Software\Python\PythonCore\2.6\Help\PythonwinReference[None]='c:\\Python26\\Lib\\site-packages\\PyWin32.chm'
Pythonwin has been registered in context menu
Creating directory c:\Python26\Lib\site-packages\win32com\gen_py
Shortcut for Pythonwin created
Shortcut to documentation created
The pywin32 extensions were successfully installed.`
(On WinXP SP3)
Had the above noted errors with my python27 pywin32 installation that got installed after my installation of ArcGIS on a windows2008 R2 server (trying to centralize our scripts).
Found that for me, I had to start a command line window with run as adminstrator (right click to get that option in windows) and then run the following command line from the c:\arcpy27\arcgis10.1>python c:/arcpy27/arcgis10.1/scripts/pywin32_postinstall.py -install
I see a lot of people have run into this issue and I tried multiple things, but this was finally the solution that managed to get pywin32 installed.
Thanks so much for your solution. Took me a couple of install and uninstalls before I finally ran across your solution and modified it for my version.

Categories

Resources