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.
Related
I am a beginner trying to learn Python. I wrote a program using Geany and would like to build and execute it but I keep getting this error: "The system cannot find the path specified". I believe I added the right info to the Path though:
Compile C:\Python373\python -m py_compile "%f"
Execute C:\Python373\python "%f"
this doesn't work. Can anyone help me figure it out. Thank you.
You have to be sure about the path of the python. So use this
import sys
print(sys.path)
For Python36 the path is as following:
C:\Users\user\AppData\Local\Programs\Python\Python36
In Python 3
Under 'Python commands', look for the 'Compile' line. Enter the following in the 'Command' box. Make sure you get the spaces right. You should have 'C:\Python34\python' followed by a space, and the rest of the command. If you have 'Python 34', with a space between Python and 34, Geany will not be able to run your code. Also, make sure your capitalization matches what you see here exactly.
C:\Python34\python -m py_compile "%f"
or use the path as the following
C:\Users\user\AppData\Local\Programs\Python\Python36 -m py_compile "%f"
Under 'Execute commands', look for the 'Execute' line. Enter the following in the 'Command' box, paying attention once again to the spaces.
C:\Python34\python "%f"
or
C:\Users\user\AppData\Local\Programs\Python\Python36 "%f"
Test your setup by running hello.py again.
Python 2
If you installed Python 2.7 instead of Python 3, the commands you want are probably:
C:\Python27\python -m py_compile "%f" or path of your python -m py_compile "%f"
and
C:\Python27\python "%f" or path of your python "%f"
See this link for more information:http://introtopython.org/programming_environment_windows.html
#Bryan McCormack,
At the Compile and Execute command field only, type python (of course matching the small letter case as in python.exe) without specifying the full python directory. Like:
Compile: python -m py_compile "%f"
Execute: python "%f"
Then just click OK, and Compile and Execute. Hope it will run the program well. If also, at the time of python installation there is no environment path is set, then set the python directory to the environment variable using command set or manually from the Control Panel > System > Advanced System Setting > Environment Variables > Path
NB: All the Configuration settings of Geany Execute command can be found at the Geany_install_directory\data\filedefs\filetypes.python for python file type at line:
[build_menu]
FT_00_LB=_Compile
FT_00_CM=python -m py_compile "%f"
EX_00_LB=_Execute
EX_00_CM=python "%f"
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
How can I wrap in the f2py module?
I mean, I am reading a few tutorials that say I should execute
f2py FIB1.f -m FIB2 -h FIB1.pyf
However, I don't know where I have to execute that, for sure not in spyder or I am doing something wrong.
Why?
Because I execute this code that should create the extension module of Fortran with Python from my subroutine in Fortran, however an error is generated.
my Fortran subroutine:
SUBROUTINE FIB(A,N)
INTEGER N
REAL*8 A(N)
DO I=1,N
IF (I.EQ.1) THEN
A(I) = 0.0D0
ELSEIF (I.EQ.2) THEN
A(I) = 1.0D0
ELSE
A(I) = A(I-1) + A(I-2)
ENDIF
ENDDO
END
What I'm executing in Python:
import numpy.f2py as f2py
f2py FIB1.f -m FIB2 -h FIB1.pyf
The error is this one:
runfile('F:/SLB/Larryf2py/teste.py', wdir='F:/SLB/Larryf2py')
File "F:/SLB/Larryf2py/teste.py", line 9
f2py FIB1.f -m FIB2 -h FIB1.pyf
^
SyntaxError: invalid syntax
As far as I know, not sure, It should generate something like:
# File setup.py
def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration('',parent_package,top_path)
config.add_extension('m',
sources = ['m.pyf','foo.c'])
return config
if __name__ == "__main__":
from numpy.distutils.core import setup
setup(**configuration(top_path='').todict())
This example of what is generated is to C but I think its something like that to Fortran too.
What I think? That I should run the first code in another place of the Python...
I tried to reproduce this.
Are you adding f2py command inside your Python code? If yes, that's not good.
The line f2py FIB1.f -m FIB2 -h FIB1.pyf needs to be in command line, not inside any *.py script.
From F2PY Users Guide and Reference Manual
f2py is a program/compiler from The purpose of the F2PY –Fortran to Python interface generator– project is to provide a connection between Python and Fortran languages. F2PY is a Python package (with a command line tool f2py and a module f2py2e) that facilitates creating/building Python C/API extension modules that make it possible.
In additon, here is detailed explanation on how to use f2py .
There might be some other problems in OP's question but for the moment most vital is this one. Like the Fortran subrotuine is not using implicit none, etc.
Well I found an answer.
Looks like in this version of anaconda one is supossed tu put like
Python c:\user\anaconda3\scripts\f2py.py FIB1.f -m FIB2 -h FIB1.py
so this way that f2py.py part was substituted for all of that. For sure I'll have more trouble in the future with this module but so far my doubts are clear.
If you want to convert fortran into a python object using a python code, the following will work:
from numpy import f2py
with open('path_to_fotran_code') as sourcefile:
sourcecode = sourcefile.read()
f2py.compile(sourcecode, modulename='test_module', verbose=1,
extra_args= '--verbose'
'--compiler=mingw32')
import test_module
In case you do not have mingw32 you can use --compile=msvc (I ran into problems trying to use msvc which I could never solve with all the internet help).
Also ensure that your windows path environment is configured to point the fortran compiler path.
f2py is not a Python command, you cannot execute it in the Python shell or inside a .py source file. It is an executable command. You must execute it in your system's shell.
You still did not answer which operating system you have, but if it is Windows, you must run it in the CMD.exe command prompt or in PowerShell. If it is Linux or similar, run it in bash or similar shell. You must run it in the same directory (folder), where the Fortran source file is located.
This problem started while I was installing pyswip and needed to run a setup.py file. Using the command "python setup.py", I'm greeted with the following message: "python: can't open file 'setup.py': [Errno 2] No such file or directory."
I know this question's been asked a lot before, so I've tried everything in previous answers. Including #!/usr/bin/env python or #!/usr/bin/env python-3.3.0 at the very top of the script and then trying "chmod +x setup.py"
gives the following: "chmod: cannot access setup.py': No such file or directory".
Trying to run other .py files from the terminal gives the same result.
Running the file in the Python Shell from IDLE doesn't do anything.
Running the "ls -d */" command shows that the Python-3.3.0/ directory, where the .py files in question are, is definitely there.
Am I missing something really obvious? (If it helps, I have Elementary OS 0.2.)
When you run python setup.py that requires the setup.py file to be in the current directory.
You can control the current directory with the cd command.
So:
cd /home/acacia/Python-3.3.0/PySwip/pyswip-0.2.3
python setup.py install
I have no knowledge about Elementary OS but you could try to use the full path of the setup.py.
python /home/acacia/Python-3.3.0/PySwip/pyswip-0.2.3/setup.py install
[EDIT] Can't answer comments, so I just added the install parameter in my answer
You need to go into the directory that you are going to "setup". For example, if you are installing numpy, and you have git-cloned it, then it probably is located at ~/numpy. So first cd into ~/numpy, and the type the commend like "python setup.py build" there.
after trying to build a standalone by entering
python pyinstaller.py -F myscript.py
in the pyinstaller directory i get an error:
error: Requires at least one scriptname file or exactly one .specfile
I have the script in the same directory as the pyinstaller. What might be causing the error?
EDIT: To answer the comments: I run the command from the same directory as pyinstaller. I can access both files.
Try adding -m after python.
Also, from what I have seen, and tried, "pyinstaller.py" doesn't work, but after removing the ".py" it works
So, perhaps you can try the following:
python -m PyInstaller -F myscript.py
Note: 'PyInstaller' in this case is case sensitive, it doesn't work if you just use 'pyinstaller'
'pyinstaller' does work however in the following case: pyinstaller -F myscript.py