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
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.
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.
I wrote a Python program in Jupyter Notebook. The program uses libraries installed through Anaconda. I need to get a separate executable Python file that would work on forks of Ubuntu and Debian.
I created the .py file from the .ipynb file through the menu in the Jupyter Notebook:
File -> Download as -> Python (.py).
Next, I try to run .py file through the Terminal in Linux:
>>> python3 name_of_created_file.py
And I get an error:
Traceback (most recent call last):
File "name_of_created_file.py", line 11, in <module>
import pandas as pd
ModuleNotFoundError: No module named 'pandas'
As I understand it, there are not enough software libraries to run the program. On the same computer (Linux) in Jupyter Notebook, my program works well.
How to get a working program separately from Jupiter Notebook? To do this, I need to separately install software libraries?
Can you please check the version of python in your local, whether python or python3. Your issue might be because of two different python versions.
Depending upon your version of python in local machine, you might have to use the same version of pip to install pandas.
Check the version of python you are running in Jupyter.
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.
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.