I have the following code:
import sys
reload(sys)
sys.setdefaultencoding('utf8')#@UndefinedVariable
import phantomjs
if __name__ == '__main__':
print ';'.join(sys.path)
I followed sth's answer in Permanently add a directory to PYTHONPATH
and added the phantomjs.pth file to ~/.local/lib/python2.7/site-packages which is where
python -c 'import site; site._script()' --user-site
told me I needed to add the pth files. In the phantomjs.pth file, I put the path where the phantomjs.py file is: /workspace/rankingmodel
It works for the python interpreter as
print ';'.join(sys.path)
prints out (amongst others) /workspace/rankingmodel but eclipse marks
import phantomjs
with the error
Unresolved Import
How can I make that Eclispe and PyDev see the PYTHONPATH which I put in the .pth file?
One easy answer is to click on the Project menu, then Properties, then under the PyDev - PYTHONPATH section click the External libraries tab and add again the required paths there.
This is the workaround I am currently using.
But I was wondering if there was a better solution where eclipse can see the global paths itself, without having to be told explicitely.
The problem is with *.pth files which are not automatically updated in Eclipse PyDev. So the solution is to remove and then re-add the python interpreter in Eclipse.
I found the answer which I was looking for in the answer by Praveen Gollakota here: Importing using pydev and .pth files
For Linux, for Eclipse Kepler PyDev 3.9.1:
Drop down menu "Window", select "Preferences" On the left-side menu: PyDev->Interpreters->Python Interpreter Remove and re-add the python interpreter, and when you add it again make sure to click all the desired global python paths.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.