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"
Related
So, I have Anaconda, OSGeo and Python2.7 installed on my computer.
I'm also using Spyder. In Spyder :
>>> import sys
>>> sys.executable
'C:\\ProgramData\\Anaconda3\\pythonw.exe'
Which is what I want.
However, in the windows command line and powershell :
$ python3
>>> import sys
>>> sys.executable
'C:\\Progra~1\\OSGeo4W\\bin\\python3.exe'
Which is not what I want. I want to use 'C:\\ProgramData\\Anaconda3\\pythonw.exe' (or python.exe, not sure) when using python3 in the command line.
Also :
$ pip3
Fatal error in launcher: Unable to create process using '"'
I don't get why python3 in the windows command line points to OSGeo's version of Python3. Here is my path :
C:\Python27\;C:\Python27\Scripts;C:\ProgramData\Anaconda3;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\Program Files\PuTTY\;C:\Progra~1\OSGeo4W\bin\;C:\Program Files\Microsoft\R Open\R-3.4.0\bin
I also have an environment variable called PYTHONHOME
C:\ProgramData\Anaconda3
Moreover (for completeness of information), I have python 2 installed :
$ python
File "C:\ProgramData\Anaconda3\lib\site.py", line 177
file=sys.stderr)
^
SyntaxError: invalid syntax
($ pip outputs the same thing).
Having python3 and python2.7 both work when using python3 and python (respectively) in the windows command line would be a nice bonus, but it's not really my priority.
There are probably several things you have to take care of:
In general the search order of the Windows PATH is from left to right starting with the system PATH. The first matching element wins. In your case this is correct because the system will search C:\ProgramData\Anaconda3\ first. However in that folder is no executable called python3 by default. On my system I created a simlink pointing to python.exe. On your system you can do it in PowerShell like this:
New-Item -Path C:\ProgramData\Anaconda3\python3.exe -ItemType SymbolicLink -Value C:\ProgramData\Anaconda3\python.exe
pip is located in Scripts\ folder so in your case you have to add C:\ProgramData\Anaconda3\Scripts to your PATH and create the corresponding simlinks again. In this case you have to create two of them because pip.exe is appending its name to the script that is trying to call (i.e. if your exe file is called foo.exe it will try to call foo-script.exe which does not exist) you can create the simlinks in PowerShell with those two commands:
New-Item -Path C:\ProgramData\Anaconda3\Scripts\pip3.exe -ItemType SymbolicLink -Value C:\ProgramData\Anaconda3\Scripts\pip.exe
and
New-Item -Path C:\ProgramData\Anaconda3\Scripts\pip3-script.py -ItemType SymbolicLink -Value C:\ProgramData\Anaconda3\Scripts\pip-script.py
Like this you will be able to use python3 and pip3 from your cmd line. Please check for similar problems with your python2 installation folder.
Hope it helps.
I installed Python 3.5 using MacPorts. I am trying to use SublimeText3 as an editor. (Anything better and more integrated tan ST3 for python development??)
From the MacOSX terminal, I can 'import numpy' just fine, but SublimeText3 cannot find the packages.
Is it because the python packages are installed as 'Frameworks'?, because the Path for finding those modules is not right?, other????
Here's what terminal shows:
$ type -a python3
python3 is /opt/local/bin/python3
python3 is /Library/Frameworks/Python.framework/Versions/3.5/bin/python3
python3 is /Library/Frameworks/Python.framework/Versions/3.5/bin/python3
python3 is /usr/local/bin/python3
Here's what ST3 shows:
File "/Users/xxx/Desktop/python_work/array_play.py", line 1, in <module>
import numpy
ImportError: No module named 'numpy'
[Finished in 0.0s with exit code 1]
[cmd: ['/Library/Frameworks/Python.framework/Versions/3.5/bin/python3', '-u', '/Users/xxx/Desktop/python_work/array_play.py']]
[dir: /Users/xxx/Desktop/python_work]
[path: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin::/Library/Frameworks/Python.framework/Versions/3.5/bin/python3/site-packages]
As you can see, I tried to add
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages
to the Path variable, since this is the location of the numpy folder, but this doesn't work...
Should I just ignore this message in ST3 and use it only as an editor??? Seems rather silly to have an IDE and not be able to build and run programs from it...
First, you need to find out which python3 you are using in terminal. You can do this by running command which python3. Suppose the output is: /Users/username/.anaconda3/bin/python3.
Second, try to set PYTHONPATH environment variable in Sublime's settings. Go to Preferences -> Settings User, and add the following lines at the end of the settings file (but inside of the last } symbol).
"env":
{
"PYTHONPATH":"/Users/username/.anaconda3/bin"
}
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.
I'm working on several Python projects who run on various versions of Python. I'm hoping to set up my vim environment to use ropevim, pyflakes, and pylint but I've run into some issues caused by using a single vim (compiled for a specific version of Python which doesn't match the project's Python version).
I'm hoping to build vim into each of my virtualenv directories but I've run into an issue and I can't get it to work. When I try to build vim from source, despite specifying the Python config folder in my virtualenv, the system-wide Python interpreter is always used.
Currently, I have Python 2.6.2 and Python 2.7.1 installed with several virtualenvs created from each version. I'm using Ubuntu 10.04 where the system-default Python is 2.6.5. Every time I compile vim and call :python import sys; print(sys.version) it returns Python 2.6.5.
configure --prefix=/virtualenv/project --enable-pythoninterp=yes --with-python-config-dir=/virtualenv/project/lib/python2.6/config
Results in the following in config.log:
...
configure:5151: checking --enable-pythoninterp argument
configure:5160: result: yes
configure:5165: checking for python
configure:5195: result: /usr/bin/python
...
It should be /virtualenv/project/bin/python. Is there any way to specify the Python interpreter for vim to use?
NOTE: I can confirm that /virtualenv/project/bin appears at the front of PATH environment variable.
I'd recommend building vim against the 2 interpreters, then invoking it using the shell script I provided below to point it to a particular virtualenv.
I was able to build vim against Python 2.7 using the following command (2.7 is installed under $HOME/root):
% LD_LIBRARY_PATH=$HOME/root/lib PATH=$HOME/root/bin:$PATH \
./configure --enable-pythoninterp \
--with-python-config-dir=$HOME/root/lib/python2.7/config \
--prefix=$HOME/vim27
% make install
% $HOME/bin/vim27
:python import sys; print sys.path[:2]
['/home/pat/root/lib/python27.zip', '/home/pat/root/lib/python2.7']
Your virtualenv is actually a thin wrapper around the Python interpreter it was created with -- $HOME/foobar/lib/python2.6/config is a symlink to /usr/lib/python2.6/config.
So if you created it with the system interpreter, VIM will probe for this and ultimately link against the real interpreter, using the system sys.path by default, even though configure will show the virtualenv's path:
% PATH=$HOME/foobar/bin:$PATH ./configure --enable-pythoninterp \
--with-python-config-dir=$HOME/foobar/lib/python2.6/config \
--prefix=$HOME/foobar
..
checking for python... /home/pat/foobar/bin/python
checking Python's configuration directory... (cached) /home/pat/foobar/lib/python2.6/config
..
% make install
% $HOME/foobar/bin/vim
:python import sys; print sys.path[:1]
['/usr/lib/python2.6']
The workaround: Since your system vim is most likely compiled against your system python, you don't need to rebuild vim for each virtualenv: you can just drop a shell script named vim in your virtualenv's bin directory, which extends the PYTHONPATH before calling system vim:
Contents of ~/HOME/foobar/bin/vim:
#!/bin/sh
ROOT=`cd \`dirname $0\`; cd ..; pwd`
PYTHONPATH=$ROOT/lib/python2.6/site-packages /usr/bin/vim $*
When that is invoked, the virtualenv's sys.path is inserted:
% $HOME/foobar/bin/vim
:python import sys; print sys.path[:2]
['/home/pat/foobar/lib/python2.6/site-packages', '/usr/lib/python2.6']
For what it's worth, and no one seems to have answered this here, I had some luck using a command line like the following:
vi_cv_path_python=/usr/bin/python26 ./configure --includedir=/usr/include/python2.6/ --prefix=/home/bcrowder/local --with-features=huge --enable-rubyinterp --enable-pythoninterp --disable-selinux --with-python-config-dir=/usr/lib64/python2.6/config
I would like to give a similar solution to crowder's that works quite well for me.
Imagine you have Python installed in /opt/Python-2.7.5 and that the structure of that folder is
$ tree -d -L 1 /opt/Python-2.7.5/
/opt/Python-2.7.5/
├── bin
├── include
├── lib
└── share
and you would like to build vim with that version of Python. All you need to do is
$ vi_cv_path_python=/opt/Python-2.7.5/bin/python ./configure --enable-pythoninterp --prefix=/SOME/FOLDER
Thus, just by explicitly giving vi_cv_path_python variable to configure the script will deduce everything on it's own (even the config-dir).
This was tested multiple times on vim 7.4+ and lately with vim-7-4-324.
I was having this same issue with 3 different versions of python on my system.
for me the easiest thing was to change my $PATH env variable so that the folder that has the version of python I wanted was (in my case /usr/local/bin) was found before another.
During my compiling vim80, the system python is 2.6, I have another python 2.7 under ~/local/bin, I find that, to make the compiling work:
update $PATH to place my python path ahead
add a soft link, ln -s python python2 ( the configure file would try to locate python config by probing python2 )
make distclean before re-run ./configure to make sure no cached wrong value is picked.
I want to run a python script without explicitly having to call "python" every time in my shell. I've tried to add the shebang #!/path/to/python but this does not seem to work. Does anyone know a work around this? Many thanks.
You've got to add the shebang:
#!/usr/bin/env python
Then make the script executable:
chmod +x foo
Then you can run it like any other executable:
./foo
And a note from Homer6: if you're editing the file from windows and invoking it on linux, you may run into the cryptic "No such file or directory" error. It's due to the line endings of the lines being CRLF instead of LF. If you convert them to LF, the script will execute as expected. Notepad++ > View > Show Symbols > Show End of Line to show the EOL characters. And Notepad++ > Edit > EOL Conversion > Unix Format to convert all line endings to use LF. Alternatively, you can use the dos2unix tool (dos2unix foo.py), which is present on most Linux systems.
It didn't really apply to your personal scripts but as you are quoting beets, note that it is also possible to automate this action when you are distributing your packages, thanks to setuptools entry_point option.
So if you are distributing a package like myModule and want to make the main_function() function accessible via typing mymodulescript in the console you would probably add something like this to your setup.py file :
setup(
# your other arguments ..
entry_points={
'console_scripts': [
'mymodulescript = myModule:main_function'
]
}
)
Add a line at the top of your script:
#! /usr/bin/env python
Rename your script from script_name.py to script_name
make the script executable: chmod +x script_name
The line at the top selects the same python that you get when typing python at the prompt. You can also specify a direct path:
#!/opt/python/3.6/bin/python
Another workaround could be to use an alias defined in the .bashrc :
e.g. add the following line in your .bachrc file :
alias mypythonalias="python mypyrhonfile.py"
type in terminal :
source ~/.bashrc
and then you may simply type:
mypythonalias
to execute the python file.
Ensure you are able to run /path/to/python on your terminal. And make sure you have given execute permission for your python file. You can give permission for the file by
chmod +x mypythonfile.py