1

I am not sure if this is a Python or a PyCharm question. I think that it is quite simple, but I could not find a solution anywhere.

I have started to write a collection of modules with utility stuff. Now I want to import one of my packages in several of my other projects. What do I have to do to be able to simply write import my_module, so that Python finds the right one automatically?

I would like to set this up on a Mac and a PC, so advice on both platforms is appreciated.

Andriy Ivaneyko
  • 20,639
  • 6
  • 60
  • 82
Fabian
  • 4,001
  • 4
  • 28
  • 59
  • Possible duplicate of [How do I import modules in pycharm?](http://stackoverflow.com/questions/19885821/how-do-i-import-modules-in-pycharm) – Dan Cornilescu Sep 01 '16 at 18:05

1 Answers1

4

It's not pyCharm issue. You have to give python information of the place your module live, to do that update PYTHONPATH, if you're using bash (OS X,GNU/Linux distro), add this to your ~/.bashrc or ~/.bash_profile

export PYTHONPATH="${PYTHONPATH}:/path/to/my_module"

Also you can checkout that article How do I set PYTHONPATH and SO How to use PYTHONPATH question to get more info.

To avoid duplicating answer adding a link to give info of how to update PYTHONPATH on Windows: How to add to the pythonpath in windows 7?

After you should be able to import your module.

Community
  • 1
  • 1
Andriy Ivaneyko
  • 20,639
  • 6
  • 60
  • 82
  • Wow, I can even modify the search paths at runtime. https://docs.python.org/3.5/library/sys.html?highlight=sys.path#sys.path – Fabian Aug 31 '16 at 10:32
  • sure,you can :) But likely you have to do it in each package, where you are going to import your module, in other turn PYTHONPATH would work for all packages at once... – Andriy Ivaneyko Aug 31 '16 at 10:38
  • 1
    Right, and PyCharm cannot "see" the module content, so there is no autocompletion... – Fabian Aug 31 '16 at 10:45