Path question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Path question

Phil-2
This seemingly simple operation has me scratching my head.

I have a python script that I want to add to the system menu. I cannot
run "python3 /path_to_the_script/thescript" outside of it's directory
because "thescript" needs resources that are also in that directory. Of
course, "thescript" will run from it's own directory
(/home/phil/Downloads/Ink_spill).

In an attempt to solves this problem I've added the directory to the
path but there's something odd going on here, as follows:

phil@phil-ThinkPad-T420:~$ cat $PATH
cat:
'/home/phil/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/phil/Downloads/Ink_spill':
No such file or directory

phil@phil-ThinkPad-T420:~$ cd /home/phil/Downloads/Ink_spill

pwd

phil@phil-ThinkPad-T420:~/Downloads/Ink_spill

cat $PATH indicates the directory doesn't exist but it does. What's
going on?

--
Regards,
Phil


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Path question

Peter Teuben-2
Not sure why you want to cat the path, echo might make more sense. But it seems what you need is setting the $PYTHON_PATH to get resources in that directory.

On Mon, Oct 12, 2020, 00:42 Phil <[hidden email]> wrote:
This seemingly simple operation has me scratching my head.

I have a python script that I want to add to the system menu. I cannot
run "python3 /path_to_the_script/thescript" outside of it's directory
because "thescript" needs resources that are also in that directory. Of
course, "thescript" will run from it's own directory
(/home/phil/Downloads/Ink_spill).

In an attempt to solves this problem I've added the directory to the
path but there's something odd going on here, as follows:

phil@phil-ThinkPad-T420:~$ cat $PATH
cat:
'/home/phil/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/phil/Downloads/Ink_spill':
No such file or directory

phil@phil-ThinkPad-T420:~$ cd /home/phil/Downloads/Ink_spill

pwd

phil@phil-ThinkPad-T420:~/Downloads/Ink_spill

cat $PATH indicates the directory doesn't exist but it does. What's
going on?

--
Regards,
Phil


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Path question

Phil-2
On 12/10/20 3:43 pm, Peter Teuben wrote:
> Not sure why you want to cat the path, echo might make more sense.
Thanks Peter, I'd forgotten about the echo command and that removes the
"No such file" message.
> But it seems what you need is setting the $PYTHON_PATH to get
> resources in that directory.

I'll play with that see if it helps.

--

Regards,
Phil


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Path question solved

Phil-2
In reply to this post by Peter Teuben-2
On 12/10/20 3:43 pm, Peter Teuben wrote:
>  you need is setting the $PYTHON_PATH to get resources in that directory.

That was, of course, the answer. Thanks again Peter.

--

Regards,
Phil


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Path question solved

Akash Rao
:)

On 12-Oct-2020 11:37, "Phil" <[hidden email]> wrote:
On 12/10/20 3:43 pm, Peter Teuben wrote:
 you need is setting the $PYTHON_PATH to get resources in that directory.

That was, of course, the answer. Thanks again Peter.

--

Regards,
Phil


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Path question

Chris Green
In reply to this post by Phil-2
On Mon, Oct 12, 2020 at 02:40:52PM +1000, Phil wrote:

> This seemingly simple operation has me scratching my head.
>
> I have a python script that I want to add to the system menu. I cannot run
> "python3 /path_to_the_script/thescript" outside of it's directory because
> "thescript" needs resources that are also in that directory. Of course,
> "thescript" will run from it's own directory
> (/home/phil/Downloads/Ink_spill).
>
> In an attempt to solves this problem I've added the directory to the path
> but there's something odd going on here, as follows:
>
> phil@phil-ThinkPad-T420:~$ cat $PATH
> cat: '/home/phil/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/phil/Downloads/Ink_spill':
>
> No such file or directory
>
> phil@phil-ThinkPad-T420:~$ cd /home/phil/Downloads/Ink_spill
>
> pwd
>
> phil@phil-ThinkPad-T420:~/Downloads/Ink_spill
>
> cat $PATH indicates the directory doesn't exist but it does. What's going
> on?
>
The 'cat' command simply tries to open the whole of the string
contained in $PATH as if it was a file.  Since there is no file
'/home/phil/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/phil/Downloads/Ink_spill'
you get the error message.

--
Chris Green

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
R C
Reply | Threaded
Open this post in threaded view
|

Re: Path question

R C
In reply to this post by Phil-2
might be a little late, but just saw this.


Why don't you set the working/current directory in your script? That way
you can execute it from "anywhere", and it sets it's own current
directory to where ever you want it, without having to do all kinds of
trickery with environment variables. Any language has a way to do that.


Ron



On 10/11/20 10:40 PM, Phil wrote:

> This seemingly simple operation has me scratching my head.
>
> I have a python script that I want to add to the system menu. I cannot
> run "python3 /path_to_the_script/thescript" outside of it's directory
> because "thescript" needs resources that are also in that directory.
> Of course, "thescript" will run from it's own directory
> (/home/phil/Downloads/Ink_spill).
>
> In an attempt to solves this problem I've added the directory to the
> path but there's something odd going on here, as follows:
>
> phil@phil-ThinkPad-T420:~$ cat $PATH
> cat:
> '/home/phil/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/phil/Downloads/Ink_spill':
> No such file or directory
>
> phil@phil-ThinkPad-T420:~$ cd /home/phil/Downloads/Ink_spill
>
> pwd
>
> phil@phil-ThinkPad-T420:~/Downloads/Ink_spill
>
> cat $PATH indicates the directory doesn't exist but it does. What's
> going on?
>

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: Path question

Phil-2
On 19/10/20 1:39 pm, R C wrote:
> might be a little late, but just saw this.
>
>
> Why don't you set the working/current directory in your script?

Thanks Ron for you suggestion. After a good night's sleep I had solved
the problem with a simple bash script.

--

Regards,
Phil


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
R C
Reply | Threaded
Open this post in threaded view
|

Re: Path question

R C

Hi Phil,

I was a little late reading the posts, but when it works it works.


just in case you were curious:

it takes '3' lines, but can wrie it as a one liner;

The first command line option, index 0 is the "command" it is executed with;  argv[0] it always exists

in python:  sys.argv[0]

then, get the "directory name" from it; the basename  in python: os.path.basename(path)

for example (basename('/my/path/to/script.py") would be "/my/path/to"

then change to that directory:  chdir;  in python : os.chdir()


so at the beginning of your python script a line like:

os.chdir(os.path.basename(sys.argv[0]));


should do that trick



just a thought.


Ron






On 10/18/20 11:26 PM, Phil wrote:
On 19/10/20 1:39 pm, R C wrote:
might be a little late, but just saw this.


Why don't you set the working/current directory in your script?

Thanks Ron for you suggestion. After a good night's sleep I had solved the problem with a simple bash script.


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
R C
Reply | Threaded
Open this post in threaded view
|

Re: Path question

R C

oops...   I meant dirname instead of basename

On 10/18/20 11:47 PM, R C wrote:

Hi Phil,

I was a little late reading the posts, but when it works it works.


just in case you were curious:

it takes '3' lines, but can wrie it as a one liner;

The first command line option, index 0 is the "command" it is executed with;  argv[0] it always exists

in python:  sys.argv[0]

then, get the "directory name" from it; the basename  in python: os.path.basename(path)

for example (basename('/my/path/to/script.py") would be "/my/path/to"

then change to that directory:  chdir;  in python : os.chdir()


so at the beginning of your python script a line like:

os.chdir(os.path.basename(sys.argv[0]));


should do that trick



just a thought.


Ron






On 10/18/20 11:26 PM, Phil wrote:
On 19/10/20 1:39 pm, R C wrote:
might be a little late, but just saw this.


Why don't you set the working/current directory in your script?

Thanks Ron for you suggestion. After a good night's sleep I had solved the problem with a simple bash script.


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users