LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-04-2016, 03:17 AM   #1
chris_crunch
Member
 
Registered: Jan 2016
Location: Braintree, Essex
Distribution: Ubuntu 14.04
Posts: 107

Rep: Reputation: Disabled
How to use $PYTHONPATH


I've continually searched this on google but I'm unable to get the full picture behind whats going on (I'm quite technically illiterate, still learning...)

I have a software program called caffe. It says:

Add the module directory to your $PYTHONPATH by export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH or the like for import caffe.

But I keep encountering issues with his.

Code:
chris@chris-crunch:~/apps/caffe-master/python/caffe$ python
Python 2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Dec  6 2015, 18:08:32) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import caffe
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named caffe
Wehhh. Why is this happening? I thought I did everything right but can someone shed light on this to help me out?
 
Old 03-04-2016, 04:19 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,214

Rep: Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696
did you add that path to PYTHONPATH? How?
 
Old 03-04-2016, 08:27 AM   #3
chris_crunch
Member
 
Registered: Jan 2016
Location: Braintree, Essex
Distribution: Ubuntu 14.04
Posts: 107

Original Poster
Rep: Reputation: Disabled
I tried this

Code:
 
>>> import sys
>>> sys.path.append('home/chris/apps/caffe-master/python/caffe/pycaffe.py')
>>> import caffe
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named caffe
 
Old 03-04-2016, 11:10 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,214

Rep: Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696
probably:
sys.path.append('/home/chris/apps/caffe-master/python/caffe')
will help
 
Old 03-05-2016, 04:13 AM   #5
aragorn2101
Member
 
Registered: Dec 2012
Location: Mauritius
Distribution: Slackware
Posts: 371

Rep: Reputation: 163Reputation: 163
Hello there,

PYTHONPATH is a Bash variable which will be passed to Python once it is called. Consequently, when you will import something from inside Python, it will look into that path. So, you have to change the variable before calling python, at the Bash prompt itself:

(displays content of your actual PYTHONPATH variable)
echo $PYTHONPATH

export PYTHONPATH=home/chris/apps/caffe-master/python/caffe:$PYTHONPATH

(now you must see the modifications you have brought)
echo $PYTHONPATH

Cheers.

Last edited by aragorn2101; 03-05-2016 at 04:15 AM. Reason: To make it more readable as there are inline commands
 
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
LXer: How to change sys.path or PYTHONPATH in Python LXer Syndicated Linux News 0 12-09-2015 04:33 AM
Set pythonpath from script at boot time estratos Linux - Server 1 12-11-2011 02:39 AM
[SOLVED] PYTHONPATH and editing to search for files in a certain directory GallopingGhost Programming 1 08-01-2010 02:21 AM
Ubuntu 9.10 - Error importing python modules - $PYTHONPATH? km0r3 Linux - Software 4 12-06-2009 09:18 PM
no ~.bashrc ~.bash_profile. Pythonpath always bringing errors when using compiz, etc. Romanus81 Slackware 3 05-22-2008 10:29 PM


All times are GMT -5. The time now is 02:52 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