PyCharm does not recognize modules installed in development mode

后端 未结 8 1503
猫巷女王i
猫巷女王i 2020-12-14 00:37

I have two pure python projects in PyCharm 3.4.1 Professional Edition. The first one, let\'s call it p (like package), is structured as a setuptools package (i.

相关标签:
8条回答
  • 2020-12-14 01:06

    I just had same problem like yours.

    Seems pycharm can not recognize module installed directly by setup.py, but can recognize module installed by pip. Finally, I use pip install src_path, but I got to pip install it everytime I modify source code.

    0 讨论(0)
  • 2020-12-14 01:13

    As of Pycharm 2016.1.4 (professional edition), it seems that opening a different project (e.g. through Open Recent) and then opening the original one makes Pycharm reindex the installed packages and hence recognize the develop-installed packages.

    This is enough for me.

    0 讨论(0)
  • 2020-12-14 01:15

    I have Just installed package using Pycharm then problem solved.

    0 讨论(0)
  • 2020-12-14 01:15

    The problem could be your interpreter path. Check where the interpreter is pointing to. In most cases it is ~/PycharmProjects/trials/venv/bin/python and this could be pointing to a python bath installed as part of Pycharm

    Change the softlink of python to your /usr/bin/python path and things should work fine

    0 讨论(0)
  • 2020-12-14 01:19

    Solution

    • go to settings->project interpreter.
    • click wheel framed (settings gear icon) button.
    • In the drop-down list, click Show all.... The available interpreters show up in the Project Interpreters dialog.

    • Select the desired interpreter.

    • In the toolbar of the Project Interpreters dialog box, click the button icon show paths (last option). The existing paths of the selected interpreter show up in the Interpreter Paths dialog box.

    • Add your package's path (package that you pip developed) here.ex /home/../repo-name

    voila!! you are good to go.

    Explanation
    Each project refers to an interpreter which you can find in settings->project interpreter. Now this interpreter uses a bunch of Paths to look for a library. By default it has site-packages and bunch of other paths there.
    Now since you used pip develop -e or python setup.py develop, a dynamic link is created pointing to your package's repository instead of a package installation in site-packages directory. So our package's source path is not here, What we need to do is to add our source path to interpreter's Paths to make it work

    Ref:

    1. https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000019690-PyCharm-not-recognize-development-library-
    2. https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-reloading-interpreter-paths.html
    0 讨论(0)
  • 2020-12-14 01:22

    In the project pane, the directory which holds p needs to be marked as source. Available under: Right-click -> "Mark Directory As" -> "Sources Root".

    Note: This setting will also add it to PYTHONPATH during execution from the run menu if the corresponding check box for the option is checked in "Edit Configurations" (default).

    0 讨论(0)
提交回复
热议问题