{"id":231,"date":"2016-12-14T18:58:21","date_gmt":"2016-12-15T02:58:21","guid":{"rendered":"https:\/\/www.actinia.me\/?p=231"},"modified":"2018-01-18T22:41:11","modified_gmt":"2018-01-19T06:41:11","slug":"some-problems-about-configuring-pydev-console-in-eclipse","status":"publish","type":"post","link":"https:\/\/www.actinia.me\/?p=231","title":{"rendered":"Some problems about configuring pydev console in eclipse."},"content":{"rendered":"<p>  I&#8217;m planning to do some java coding now. So I installed eclipse which allows me to work with both python and java. However I was really annoyed at configuring the pydev console.<br \/>\n  Firstly, I found I can not interact with the console if I run the script with &#8220;run&#8221; button.<strong> I must activate an interactive console<\/strong> to do some further interaction. But the pydev&#8217;s console behaves in an odd manner, at least, that&#8217;s how it seems to me.<br \/>\n  The interactive console can not import modules right there in the same directory with the current working script. The solution is to <strong>add the project&#8217;s directory to pydev&#8217;s PYTHONPATH<\/strong>: right click project name &#8211;>PyDev&#8211;>set as source folder (add  to PYTHONPATH).<br \/>\n  Then comes the next problem. I have two similar projects. Both of them rely on a ui.py script of its own. To run these projects, I have to add their directory to Python path as described above. Then I ran project1, everything is fine. Then I ran project2, some error occured. It turns out that project2 called ui.py(1) insteat of its own ui.py. Obviously, the pythonpath configuration does not work in my situation. I have to try another solution, that is to <strong>add the projects&#8217;s directry to their external lib<\/strong>.<br \/>\n  But I still can&#8217;t get my project to run correctly. This time, the console failed to find a xls file which was supposed to be read. I typed <code>import os; print(os.getcwd())<\/code> to see the current working directory. It turns out that the interactive console was working under eclipse&#8217;s default working path rather than the project&#8217;s path. So, I have to <strong>edit the initial command of interactive console<\/strong> to force the console to change it&#8217;s working directory at start up. Go to Windows&#8211;>preferences&#8211;>Pydev&#8211;>interactive console&#8211;>initial command, change the initial interpreter commands to:<\/p>\n<p><code>import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))<br \/>\nimport os<br \/>\nimport inspect<\/p>\n<p>__old_runfile = runfile<\/p>\n<p>def runfile(file):<br \/>\n    curpath = os.path.dirname(os.path.abspath(file))<br \/>\n    os.chdir(curpath)<br \/>\n    __old_runfile(file)<\/code><\/p>\n<p>  Now I can properly run my project. I have solved all the problems though, I think I will not use eclipse a lot on python coding. I&#8217;d still like to use spyder which is far more cute than eclipse especially in virtual environment. It really saved you a lot of time from configuring all these paths and resourses<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m planning to do some java coding now. So I installed eclipse which allows me to work with both python and java. However I was really annoyed at configuring the pydev console. Firstly, I found I can not interact with the console if I run the script with &#8220;run&#8221; button. I must activate an interactive [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/posts\/231"}],"collection":[{"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.actinia.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=231"}],"version-history":[{"count":2,"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/posts\/231\/revisions"}],"predecessor-version":[{"id":233,"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/posts\/231\/revisions\/233"}],"wp:attachment":[{"href":"https:\/\/www.actinia.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.actinia.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.actinia.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}