LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-10-2010, 03:42 PM   #1
dlemper
LQ Newbie
 
Registered: Oct 2010
Posts: 5

Rep: Reputation: 1
Can a PATH statement be used with Python in Ubuntu 9.10 ( Debian linux ) ?


On Ubuntu 9.10 I installed Python 3.1.1 successfully with Synaptic Package Manager. However the Python interpreter cannot find my scripts, currently in /home/dave/pycode.
Tried to append PATH with $ PATH=$PATH:/home/dave/pycode
$ export PATH
This appends _temporarily_ but python remains clueless about location of my scripts. Rebooted and $ echo $PATH shows the
:home/dave/pycode has been dropped.
Searched Internet and some speak of .rc or .bashrc or .profile
files. Found some of these and opened with Komodo : they are Linux script files and I am clueless as to how to modify.
Currently I can import my scripts only if I change to the /pycode dir before running.
Lutz's Python book says to change PATH file - Ha .
Sobell's "A practical Guide to Ubuntu Linux" is no help.
Ubuntu's own on line help is worth less than a fart in a hurricane. Ubuntu's gedit would not even open bash.bashrc.
Dave
 
Old 10-10-2010, 09:38 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,817

Rep: Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408
"I am clueless as to how to modify."
odd ,seeing as you are using a bunch of your own scripts in "/home/dave/pycode. "

the /etc/bashrc (/etc/bashrc.local) or file and /etc/profile file should be very well documented ( at the top of the files, and in the file it's self )
Komodo ? why do you need a IDE to edit a normal everyday text file ?
nano or Vi or
gedit, kwrite , scite ,emacs or any text editor can open the two ( even the wine "notepad.exe")
but you NEED to be root to change them - as normal/usual in all versions of Linux

BUT those files are for SYSTEM-WIDE settings

look in your home, $HOME, ~ folder for a . ( dot ) file
.bash_profile or ~.profile
and edit those
 
1 members found this post helpful.
Old 10-10-2010, 10:28 PM   #3
dlemper
LQ Newbie
 
Registered: Oct 2010
Posts: 5

Original Poster
Rep: Reputation: 1
John,
Thanks for your reply.
There are no files in my /home directory , hidden or otherwise.
In /etc there is a file called profile ( & many files elsewhere containing 'profile' ).
the /etc profile file is a 28 line script file beginning :
# etc/profile : system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells ( bash(1) ... )

(line 4) if [ -d /etc/profile.d ] ; then

I'm not using Komodo-IDE but rather Komodo-Edit.
Regards, Dave
 
Old 10-10-2010, 10:33 PM   #4
mark_alfred
Senior Member
 
Registered: Jul 2003
Location: Toronto, Ontario, Canada
Distribution: Ubuntu Linux 16.04
Posts: 1,258

Rep: Reputation: 147Reputation: 147
Perhaps adding the following to /home/dave/.bashrc file would work (using any text editor):
Code:
export PATH=$PATH:/home/dave/pycode
 
Old 10-10-2010, 11:53 PM   #5
dlemper
LQ Newbie
 
Registered: Oct 2010
Posts: 5

Original Poster
Rep: Reputation: 1
Thanks Mark.
.bashrc is a 100 line long script file.
I inserted at lines 95 & 96 :
# include pycode dir in python3.1 search
export PATH=$PATH:/home/dave/pycode

Saved, closed and rebooted.
Doesn't work. Python3.1 still can't find scripts in /home/dave/pycode

Reopened .bashrc Moved above two lines to lines 6 & 7
Saved, closed & rebooted.
Doesn't work. Examined .bashrc Lines are there.
In terminal ran $ echo $PATH ->
/usr/local/sbin:/usr/local/bin . . . :/home/dave/pycode

Changed to /home/dave/pycode. The .py files are there. Called up python3.1
while in this directory. Modules can be imported.

A puzzlement. Dave, Texas
 
Old 10-11-2010, 02:12 PM   #6
mark_alfred
Senior Member
 
Registered: Jul 2003
Location: Toronto, Ontario, Canada
Distribution: Ubuntu Linux 16.04
Posts: 1,258

Rep: Reputation: 147Reputation: 147
Perhaps the PATH setting isn't the problem. Are the scripts in /home/dave/pycode executable? Perhaps trying the command "chmod a+x" on your scripts to make them executable would help.
Code:
dave@ubuntu:~/pycode$ chmod a+x yourscripts
 
Old 10-13-2010, 03:56 PM   #7
dlemper
LQ Newbie
 
Registered: Oct 2010
Posts: 5

Original Poster
Rep: Reputation: 1
Mark, thanks for your reply.
I'm not sure if you're familiar with python. If not : there
are two ways of running a script ( aka module or 'program' ):
1. Calling up python interactive interpreter by $ python3.1
In the interpreter one can import (& run) a module with
>>> import gamma
2. Executing python and the module with a single line in
Linux terminal : $ Python3.1 gamma.py

Currently I can successfully do 1. only if I'm in the pycode dir :
eg. /home/dave/pycode$ python3.1
Python interpreter will come up if called anywhere, but if
elsewhere cannot find the scripts in ~/pycode.

Can successfully do 2. only if I'm in the directory containing
Python and give the long designation of the script, eg :
/etc/python3.1$ python3.1 /home/dave/pycode/gamma.py

I believe what you suggested is the way of making a file executable
in Linux. I tried it with my gamma.py script. Makes no difference.

One small advance I made was to write a file called py :
# py bash script for starting python in pycode dir
cd /home/dave/pycode
python3.1
Went through with your suggestion $ chmod a+x py
Now if I'm in the dir containing this I can in one step
cd to pycode and call up the interpreter ~$ ./py
Attempted to put it in sbin so I could execute it anywhere -
but so far that hasn't worked.

Usable, but far from the convenience of old XP. There I have
icons for the python interpreter and notepad++ on the
desktop. Can call them up with mouse, and alternate or
overlap them. I recall a PYTHONPATH in Windows which
apparently Linux doesn't have. After installing python3.1
with Synaptic I was surprised that no icon appeared and not
even a tickler announcing a new program. Found it only by
entering python3.1 in terminal. My ( naive ) impression
is that Linux may be more powerful, but its harder to get
under the hood. Regards, Dave
 
Old 10-14-2010, 10:44 PM   #8
dlemper
LQ Newbie
 
Registered: Oct 2010
Posts: 5

Original Poster
Rep: Reputation: 1
SOLVED The python sys.path is created at runtime by the file site.py
It looks in certain directories for .pth files and incorporates
each line of these files into the list called sys.path .

This question was answered as inquiry #1 Jul 18, 2005 at
http://bytes.com/topic/python/answer...nd-my-new-path

I made a file pycode.pth consisting of the path
/home/dave/pycode
This was placed in one of the paths in the sys.path list :
/home/dave/.load/lib/python3.1/site-packages
The python3.1 interactive interpreter can now be run and sys.path contains
'home/dave/pycode' after ~/site-packages.
My scripts can now be easily imported.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find the path statement. swamprat Linux - Newbie 3 11-10-2008 12:43 AM
PATH statement from file granny Linux - Newbie 8 04-21-2005 01:58 PM
please tell me if my path statement is correct on RH 7.3 ergo_sum Linux - Newbie 9 12-13-2003 12:41 AM
PATH statement editing? cottonmouth Linux - General 2 08-17-2003 09:00 PM
Python EXEC Statement ranger_nemo Programming 3 07-24-2003 09:31 PM


All times are GMT -5. The time now is 11:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration