Mac OS Sierra.
In terminal, while trying to execute a .sh file that involves a Python script with Fortran portions, I got this message:
lenscov-master Roger$ ./run_covariances.sh recompile
rm *.o *.so
rm: *.so: No such file or directory
make: [clean] Error 1 (ignored)
gfortran -fPIC -c *.f -lgfortran -lifcore
f2py-2.7 -c loop_lensing.f90 *.o -m loop_lensing --opt=-ffixed-line-length-
none --opt=-O3
/bin/sh: f2py-2.7: command not found
make: *** [loop_lensing] Error 127
However, it is fine just test-running the .f90 file:
f2py -c loop_lensing.F90 -m test
returns a bunch of normal-looking information.
Does anyone maybe know what is going on?
it is fine just test-running the .f90 file
means you have f2py installed. But the script use f2py-2.7
You need to check the version of installed f2py, and make sure f2py-2.7 redirects to the corrent f2py.
The script (or a Makefile) tries to invoke f2py-2.7 instead of f2py. If it is your script or you can easily adjust it, rename all f2py-2.7 to f2py. Otherwise you have to tell us more about the script and show the code of the script.
As foodtooth says, make sure you have f2py 2.7 and not f2py-3, but I don't expect that to be a problem.
You could also make a symlink f2py -> f2py-2.7 for the script.
Related
I encounter a problem on using the matplotlib-cpp in MacOS. Recently I download the matplotlibb-cpp into my macbook and try to run the sample code to see whether it works properly. I compile the sample code using
g++ test.cpp -std=c++17 \
-I /Users/pangkachun/matplotlib-cpp \
-I /Users/pangkachun/miniforge3/include/python3.9 \
-I /Users/pangkachun/miniforge3/lib/python3.9/site-packages/numpy/core/include \
-L /Users/pangkachun/miniforge3/lib \
-lpython3.9 \
-o plot
However, when I tried to execute the output file ./plot, I got an error message from terminal
dyld[47656]: Library not loaded: #rpath/libpython3.9.dylib
Referenced from: /Users/pangkachun/plot
Reason: tried: '/usr/local/lib/libpython3.9.dylib' (no such file), '/usr/lib/libpython3.9.dylib' (no such file)
zsh: abort ./plot
Could someone give me some guidelines on how to solve this problem?
""" Update"""
I use an alternative method to compile ./plot which symlink the miniforge3/lib that containing libpython3.9.dylib to /usr/local/lib. This /usrlocal/lib is created by my own under symlink. Although this works, I hope there is a "normal" method to deal with this issue.
When I try to run a makefile (type "make test" in terminal) which runs a batch file I get the equivalent error:
cd directory_path && test.bat
/bin/sh: test.bat: command not found
make: *** [makefile:58: test] Error 127
The makefile is:
.PHONY: test
test:
cd directory_path && test.bat
python path/test.py
(I changed names of the batch file, the directory path, etc. to try and make things more generic)
I can manually type "cd directory_path" and then "test.bat" and those both work. This makefile works on other systems. It only doesn't work on mine. I think it is an issue with how I installed Cygwin and how I run "make.exe".
I can use make to compile C code, but I also get an error trying to use make to run python scripts. The makefile from before also has a command for python path/test.py. This also isn't working on my system. If I delete the batch file line, but keep the python command it throws the error:
python path/test.py
make: python: No such file or directory
make: *** [makefile:59: test] Error 127.
I don't understand why it throws the error of no such file or directory since the path leads to the file, and if i put the python script in the same working directory as the makefile then it still can't find it.
Any ideas/solutions on these problems? Thank you!
EDIT:
Doug Henderson:
I started a cmd prompt at the place with the make file and entered all of these commands in
uname -a
CYGWIN_NT-10.0 james-mobl2 3.1.6(0.340/5/3) 2020-07-09 08:20 x86_64 Cygwin
which make
/usr/bin/make
make -v
GNU Make 4.3
Built for x86_64-pc-cygwin
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
which python
which: no python in
(/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09-hotspot/bin:
/cygdrive/c/windows/system32:
/cygdrive/c/windows:
/cygdrive/c/windows/System32/Wbem:
/cygdrive/c/windows/System32/WindowsPowerShell/v1.0:
/cygdrive/c/windows/System32/OpenSSH:
/cygdrive/c/Program Files/Git/cmd:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps/python:
/cygdrive/c/Program Files/PuTTY:
/usr/bin:
/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09 hotspot/bin:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps)
(I cleaned up the output a little to make it more legible). This and which test.bat are the only commands that failed.
python -V
Python 3.8.5
The change directory changed correctly
which test.bat
which: no test.bat in
(/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09-hotspot/bin:
/cygdrive/c/windows/system32:
/cygdrive/c/windows:
/cygdrive/c/windows/System32/Wbem:
/cygdrive/c/windows/System32/WindowsPowerShell/v1.0:
/cygdrive/c/windows/System32/OpenSSH:
/cygdrive/c/Program Files/Git/cmd:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps/python:
/cygdrive/c/Program Files/PuTTY:
/usr/bin:
/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09 hotspot/bin:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps)
I added cmd /c test.bat to the makefile and it worked, but I've also had the batch file run on different systems without that addition. I also have a lot batch files in the actual makefile so this solution works but isn't ideal. It also didn't fix the python script not running.
I didn't initially have cmd.exe in my path, but I added it before entering those commands.
I'm not sure what you mean by starting my PATH in bash with /usr/bin;/bin;THE_REST
MadScientist:
I was manually entering it into a Windows Terminal. Is it possible to have Cygwin invoke a Windows command.com shell?
What I did was go to directory that contained the makefile. Open a windows terminal by typing 'cmd' in the address bar. I would then type 'make test'. That obviously led to the issues. I then went through and manually entered the commands I thought the makefile was supposed to invoke. So I entered 'cd directory_path && test.bat'. This ran.
Matzeri:
I don't really know. I'm completely new to POSIX, etc. I'm guessing I'm using Windows style, and judging from other responses, I'm trying to use Cygwin to do a non-POSIX style.
Thank you, everyone for responses!
Make sure cygwin is installed with basic packages --> Some basic packages not installed with cygwin try below link to install some basic package, uninstall the cygwin and install it again with following basic package :
https://wiki.usask.ca/display/MESH/Running+Python+from+the+Cygwin+Terminal#RunningPythonfromtheCygwinTerminal-Cygwin
make sure cygwin's bin folder is added to your environment variable (e.g., C:\cygwin64\bin)
If cmd /c test.bat works then . is probably not in your PATH. Always do ./test.bat when you want to run something in the current directory. Never count on the PATH unless you have set it yourself. Also make sure the file is executable. chmod +x test.bat
Using Python 3.7, I am trying to invoke g++ to compile and build a C++ file via
#!/usr/bin/env python3
import subprocess
if __name__ == '__main__':
subprocess.run(
executable="/usr/bin/g++",
args=["/some/path/source.cpp", "-std=c++17"],
shell=True
)
When I run the script, the executable builds. I then chmod u+x it. However, when I try to execute the executable, it fails and says:
-bash: ./a.out: cannot execute binary file: Exec format error
I've read some other posts regarding this error however none are applicable. For some reason, this method fails, however when I run g++ natively in my terminal, it works as expected.
Edit: When I invoke file a.out, the output is
a.out: ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), not stripped
Appreciate any help, thanks!
The executable parameter to subprocess is only rarely needed. With shell=False, it overrides args[0] as the program to run (allowing argv[0] to be customized, as for a login shel). With shell=True (which should be avoided when possible, partly because it doesn’t do what you think with your carefully separated args list), it replaces the implicit /bin/sh invoked to run the command. The standard option to run one command is -c, so you ran
/usr/bin/g++ -c /some/path/source.cpp -std=c++17
which indeed produces a relocatable (i.e., a .o file). a.out is not the normal name for such, but perhaps it’s a fallback when the directory containing the source is not writable.
I am working on a remote server, so I have installed swig locally, using -prefix=/home/user/directory.
I have a makefile from a collegue which has the command :
swig $(SWIG_LIB) -python -c++ -threads $<, in the path home/user/dir2.
And when i run make i get :
swig -I /home/theodore/swig/share/swig/3.0.7 -python -c++ -threads tagger_swig.i
make: swig: Command not found**
I have googled like ages and I have found nothing that could make it work.
Any ideas?
Try to run it by supplying absolute path to swig binary. If it works, check if swig is in your PATH - it probably isn't. This should fix your error.
I am trying to compile & execute my hw cpp file under the python script file which we are given by lecturer. the how-to-manual.pdf he sent us it says use:
c:\>python ./submit.pyc problemID -u username -p password -b //submit.pyc is already given to us
and here is the manifest.txt we are given:
[main]
problem = gc
build =
g++ main.cpp -o solver
run =
./solver %f
my cpp file works normally like this:
./solver input_file
However, I am trying (I have to) to do this under the windows OS. I have Python 2.7.x installed and python.exe is in the Command PATH. I can't run it under the linux ssh sytem because there is 2.4.x python installed and I can't touch it (school's system).
Anyway, when I execute the line above, it returns me:
Command execution failed:
g++ solver.cpp -o solver
I think I told everything I can. So, any idea that what I have to do else? except asking to lecturer:)
For the above to work it needs to be able to find g++ so you need to add the directory that it resides in to the PATH environment variable. This can be done from within your python script or on the command line with:
path=Where\g++\lives;%path%
This will only apply within the current DOS session.
Or you can add it permanenty through system settings->advanced settings->environmental variables
You could also look at using a python virtual environments on the schools linux system.