Calling make from Python on Windows results in Makefile error - python

I need to call make build from Python script on Windows.
Since make is not available by default on Windows, I've installed GnuWin32 edition. To limit variances the only command under build is pwd
Running in cmd is OK and would print current dir. Running from Python as:
import subprocess
subprocess.run(['make', 'build'])
would result in the error:
process_begin: CreateProcess(NULL, pwd, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [build] Error 2

Resolved by adding C:\Program Files\Git\mingw64 to the path

Related

How do I run a setup.py file without being in its directory?

To install a package that includes a setup.py file, usually you cd into the root directory where setup.py is located and then run the following:
python setup.py install
Now my problem is that I'm building an addon for another application, and while I can install "normal" package via code with the following:
subprocess.run([sys.executable, "-m", "pip", "install", package])
I also have to install a couple custom made packages, and if I try to do it like this:
subprocess.run([sys.executable, "-m", "/MSN-Point-Cloud-Completion-master/emd/setup.py", "install"])
I get the following error: Error while finding module specification for 'MSN-Point-Cloud-Completion-master/emd/setup.py' (ModuleNotFoundError: No module named 'MSN-Point-Cloud-Completion-master/emd/setup')
What is annoying me is that if I manually cd into the directory and simply run python setup.py install from the cmd it works just fine.
So the problem seems to be passing the relative path to the setup.py file, but as I said, considering this is an addon I need to install that setup.py from code. Any solution?
Reading comments made me realize a few mistakes.
First of all I realized that I shouldn't use -m flag in this case and this allow me to execute setup.py correctly. Also deleted the extra slash in the path and now the following works:
subprocess.run([sys.executable, "MSN-Point-Cloud-Completion-master/emd/setup.py", "install"])
However, since I wasn't in that directory still, I also got the following error c1xx: fatal error C1083: It is not possible to open file: 'emd_cuda.cu': No such file or directory and the compilation failed.
This definitely fixed all the problems:
import os
import subprocess
os.chdir("MSN-Point-Cloud-Completion-master/emd/")
subprocess.run([sys.executable, "setup.py", "install"])

Mac OS X error: directory that is not on PYTHONPATH and which Python does not read ".pth" files from

I'm getting an error while trying to install FEnicS on Mac OS X 10.11.6. I've read the responses to similar questions on this website, and have tried the suggested solutions, but I must be doing something wrong.
On running the command:
curl -s https://fenicsproject.org/fenics-install.sh | bash
I get an error while the cython package is being installed:
[cython] Building cython/e2t4ieqlgjl3, follow log with:
[cython] tail -f /Users/sophiaw/.hashdist/tmp/cython-e2t4ieqlgjl3-1/_hashdist/build.log
[cython|ERROR] Command '[u'/bin/bash', '_hashdist/build.sh']' returned non-zero exit status 1
[cython|ERROR] command failed (code=1); raising.
The message from build.log is:
Checking .pth file support in
/Users/sophiaw/.hashdist/bld/cython/e2t4ieqlgjl3/lib/python2.7/site-packages/
/Users/sophiaw/.hashdist/bld/python/pf77qttkbtzn/bin/python -E -c pass
TEST FAILED:
/Users/sophiaw/.hashdist/bld/cython/e2t4ieqlgjl3/lib/python2.7/site-packages/
does NOT support .pth files error: bad install directory or
PYTHONPATH
You are attempting to install a package to a directory that is not on
PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/Users/sophiaw/.hashdist/bld/cython/e2t4ieqlgjl3/lib/python2.7/site-packages/
and your PYTHONPATH environment variable currently contains:
'/Users/sophiaw/.hashdist/bld/cython/e2t4ieqlgjl3/Python.framework/Versions/2.7/lib/python2.7/site-packages:'
Here are some of your options for correcting the problem:
You can choose a different installation directory, i.e., one that is on PYTHONPATH or supports .pth files
You can add the installation directory to the PYTHONPATH environment variable. (It must then also be on PYTHONPATH whenever you run Python
and want to use the package(s) you are installing.)
You can set up the installation directory to support ".pth" files by using one of the approaches described here:
https://pythonhosted.org/setuptools/easy_install.html#custom-installation-locations
Please make the appropriate changes for your system and try again.
I've tried adding this to the bash_profile, but get the same error:
export PYTHONPATH=/Users/sophiaw/.hashdist/bld/cython/e2t4ieqlgjl3/lib/python2.7/site-packages:$PYTHONPATH.
How can I fix this error?
This was resolved by the fenics support group. to install FEniCS on OS X, Docker is a more convenient option.

make: f2py: No such file or directory

I am running Mac OS X 10.10. I have some python code I have inherited. I need to run "make" in a certain directory, because I get a warning when I run my python script along the lines of WARNING: failed to import test1lib. Please run make in /this/directory/ So I go to that directory where I find the following files:
Makefile __init__.py __init__.pyc foo.py foo.pyc foo_code.f foolib.f
So I run $ make
but I get the following error:
f2py -c foolib.f -m foolib
make: f2py: No such file or directory
make: *** [foolib.so] Error 1
Running which f2py returns /usr/local/bin/f2py so its not like I don't have f2py, but why is my terminal expecting f2py to be a directory? What can I do so that I can run make on this case?
If you have f2py, then it's either not on the search PATH, or it has not been made executable.
I don't know if you are on Linux or Windows. Try to execute f2py manually and see if it starts. If not, try to locate it, and see where it is installed.
If you can start it from the command line, then show us the Makefile around where the command f2py is located.
EDIT: Ok... I'm suspecting that f2py is actually a Python script, and it has a shebang line (first line starts with #!) which calls for a python version you don't have. In my system, f2py start with:
#!/usr/bin/python
which calls python2.7.x... If you have python3, then f2py may not find it. Do you start Python with the python3 command?
Note: It seems like f2py doesn't come for Python3 ('f2py3' or so).
Note: The error message you mention can come from a wrong shebang line at the start of f2py (the shebang is the first line of the f2py executable - which is just a Python script). Normally it is
#!/usr/bin/python
or maybe
#!/usr/local/bin/python
if you compiled Python yourself. If it's neither of these, start suspecting. Maybe f2py was installed by some confused tutorial or demo.

failed to run python scripts with jenkins

I am trying to run a Python job. I have created the following folder:
C:\Users\herod\jenkins_ws\workspace\window_testing
and added the script "testing.py" to it.
The script is very simple:
if __name__ == "__main__":
print "hellow world !"
f = open('test_log.txt','w')
f.write("hello\n")
f.close
But I am getting the following error when running it from Jenkins (if I run it from command line it works):
>Building remotely on windows1 (widndows_genereal) in workspace C:\Users\herod\jenkins_ws\workspace\window_testing
[window_testing] $ python C:\windows\TEMP\hudson5234791200924972506.py
The system cannot find the file specified
FATAL: command execution failed
java.io.IOException: Cannot run program "python" (in directory "C:\Users\herod\jenkins_ws\workspace\window_testing"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at hudson.Proc$LocalProc.<init>(Proc.java:244)
at hudson.Proc$LocalProc.<init>(Proc.java:216)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:775)
at hudson.Launcher$ProcStarter.start(Launcher.java:355)
at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1024)
at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:991)
What am I doing wrong ?
Here is what I have tried:
in the configure for the job at the build section I choose "execute python script" and than entered the testing.py file - not working.
I also tried to enter there python testing.py and python.exe testing.py - not working.
Trying to write a python script in the "script" edit text - not working.
If I change the execute type from python to batch file and than it shows that it pass but actually it didn't run the python script.
update2: (after trying Technext solution) I got the next error:
Building remotely on windows1 (widndows_genereal) in workspace C:\Users\herod\jenkins_ws\workspace\window_testing
[window_testing] $ python C:\Users\herod\AppData\Local\Temp\hudson4767788636447260218.py
Traceback (most recent call last):
File "C:\Users\herod\AppData\Local\Temp\hudson4767788636447260218.py", line 1, in <module>
testing.py
NameError: name 'testing' is not defined
Build step 'Execute Python script' marked build as failure
Finished: FAILURE
Whenever running python as a command in batch file, Give the full path of Python executable or you will have to configure the path in the Jenkins environment. Say your python executable is kept in C:\Python27 folder, then execute the following:
C:\Python27\python.exe <full path of python file to execute>
Since the python script runs fine on the command line but has issues when running through Jenkins, it most probably means that the user with which Jenkins is running has issues finding Python executable i.e., python.exe. If it is possible (and feasible) for you to change the Jenkins user, then please change it using the process i described here. Make it run as the same user with which you are running the program successfully on command prompt.
When you install Python in Windows, there is an option to "Add Python to System Path" which you should make sure is selected. You can safely install over your existing Python if you're not sure. This worked for us in Jenkins using the Python plugin.

How to import fontforge to python in windows 7

Environment: Win 7, Python 3.4, Sublime Text 2
I am trying to use fontforge as in following example, by importing fontforge in *.py:
import fontforge
font = fontforge.open('blank.sfd')
...
However, I haven't found any help for win 7 on where (or which subset) to include fontforge binary in my project to make it work. Any ideas, please? Thanks
Edit:
I was trying to build it with pyextension in win 7 as described here:
http://fontforge.org/source-build.html#MS
via cygwin it fails on executing
./configure --enable-pyextension
throwing
checking for gcc
result: no
checking for cc
result: no
checking for cl.exe
result: no
error: in `/cygdrive/c/fontforge':
no acceptable C compiler found in $PATH
Edit 2:
By installing C compiler I've managed to ./configure it but my attempts have failed on executing make install command. I got following error, preceding another countless lines:
Makefile:91: recipe for target '../libfontforge.la' failed
make[1]: *** [../libfontforge.la] Error 1
make[1]: Leaving directory '/cygdrive/c/fontforge/fontforge'
Makefile:28: recipe for target 'fontforge' failed
make: *** [fontforge] Error 2
Install fontforge for windows, then search your install for a fontforge-console.bat, and double-click it. From there you have a python environment that includes fontforge via the command:
ffpython
e.g.:
ffpython yourPythonFontForgeScript.py
You may need to cd to whatever directory has your python script before running that command, or otherwise make sure that the script is in your %PATH%.

Categories

Resources