Import Statement works from PyCharm, but not from terminal

Pycharm 2016.2.3, Mac OS X 10.11.1, Python 3.5 (Homebrew);

I have this folder structure


    project
      /somepackage
        /subpackage
         bar.py
       foo.py

    foo.py:
    import somepackage.subpackage.bar
    print("foo")

    bar.py:
    print("bar")

So my expected output is

    bar
    foo

This works fine when run from PyCharm. However, when I run it from my terminal I get an ImportError:

    $ pwd
    $ /home/project (not the actual path; just omitting some personal stuff)
    $ python3.5 somepackage/foo.py
    File "foo.py", line 1, in <module>
    import somepackage.subpackage.bar
    ImportError: No module named 'somepackage'

I have found this question[1], which is about the same problem. However, none of the suggested solutions work for me, as I am indeed using the same Python interpreter as PyCharm does and I am currently in the folder that contains the `somepackage/` folder.

Does anyone have any other suggestions about how to solve this issue? Thank you kindly!



    


  [1]: http://stackoverflow.com/questions/31348711/python-works-in-pycharm-but-not-from-terminal

0
3 comments
Avatar
Permanently deleted user

If this helps anyone, I would recommend trying out

$ pip install .

This installs your own package into your Python library.

0

Hi,
I'm having the same problem, 4 years after this post.
Is there is a solution to make pycham import work the same as python3 in terminal ?
Or should we install our package everytime we modify it ?

Thanks a lot

0

Hedwin Bonnavaud

Hi, have you considered using `pip install -e` to install the package as editable ?

0

Please sign in to leave a comment.