I want run python script with:
python script
from directory /home/script-python
and how to add this directory to python path?
In script bash I put linie in .bashrc
export PATH=$PATH:/home/script-bash
python path
Re: python path
There is no special "python path". You use the same PATH as with bash or anything else. And you run it without specifying the python interpreter at all, like any program. You need to make it executable first of course.
Re: python path
Not work.
I put:
export PATH=$PATH:/home/stahoo/skrypty_python/
and
I put:
export PATH=$PATH:/home/stahoo/skrypty_python/
and
but from directory worksstahoo[~]$ python losuj.py
python: can't open file 'losuj.py': [Errno 2] No such file or directory
Re: python path
As I said, don't run it with python. Just run the executable as any other executable.
If you want to run it with python, you have to use the full path.
Code: Select all
$ losuj.py
Re: python path
bash script hello
python script losuj.pystahoo[~]$ hello
bash: /home/stahoo/skrypty_bash/hello: Brak dostepu (*access denied)
stahoo[~]$ ./hello
bash: ./hello: Nie ma takiego pliku ani katalogu (*No such file or directory)
stahoo[~]$ sh hello
hello world
stahoo[~]$ bash hello
hello world
$ losuj.py
bash: losuj.py: nie znaleziono polecenia (*command not found)
Re: python path
What does the first line of your python script look like? Is it like this? If not, try putting this as the first line:
Same thing for bash scripts:
In each case, these lines indicate that the files are scripts, and what to run them with - here, python or bash.
Secondly, are they executable?
Code: Select all
#!/usr/bin/env python
Code: Select all
#!/bin/sh
Secondly, are they executable?
Code: Select all
#chmod +x /foo/bar/lusaj.py
Re: python path
Make it executable: chmod +x /home/stahoo/skrypty_bash/hello
Re: python path
EDIT: And use export LANG=C before posting error messages.thenktor wrote:Make it executable: chmod +x /home/stahoo/skrypty_bash/hello
Re: python path
losuj.py
I make new losuj-1.py#!/bin/python
import random
random.seed()
s=random.randint(1,595)
print s
#!/usr/bin/env python
import random
random.seed()
s=random.randint(1,595)
print s
I always give chmod +x script$ export LANG=C
$ losuj-1.py
bash: losuj-1.py: command not found
Re: python path
Well, then I'm not sure what the problem is - and maybe the "env" shouldn't be there or isn't needed. I just copied from a script written by the devs to be sure it was right!
Are you sure the scripts directory is still in your $PATH? Check by doing
Sometimes the effects of changes created by export are unexpectedly patchy, but you can just reissue the command in the terminal concerned immediately before calling the script. Once you've got it working, you may want to change your .profile to include the scripts directory in $PATH.
Are you sure the scripts directory is still in your $PATH? Check by doing
Code: Select all
echo $PATH