Trouble with debugging and importing


I've setup python packaging to handle paths and this works fine at the python prompt but when I try to run Pycharm debug it seems to not respect the package import feature and unless I attach the other packages to the current project in pycharm I don't see how to get debug to import anything in the package directories.

at python prompt:
from utilities.utilities import get_ste

If I attach the project/package utilities to the current project then in pycharm I must use:
from utilities import get_ste

The problem is we have different packages containing the same module names. Since the above import drops the top level package name, importing the next package overwrites get_ste.

Is there a way to get pycharm debug to respect the existing import statements in the modules that work at the python prompt?
8 comments
Comment actions Permalink
Please describe your project structure in more detail.
PyCharm adds the roots of the project to PYTHONPATH. So if you have a directory "utilities" containing a file "utilities.py", and if you want it to be importable as "utilities.utilities", you need to add the parent directory of "utilities" as a content root to your PyCharm project.
0
Comment actions Permalink

The current project is Development/PRTS

The resources packages are
Development/utilities
Development/tools
Development/JIRA

I added the resource packages to the content list for PRTS but pc still listed the libraries as unresolved.

So I removed all content directories and added
Development

This brings in all the other unrelated packages but is this the correct approach?
0
Comment actions Permalink
Yes, this is the correct approach for your project configuration. You can exclude the unrelated stuff from being handled by PyCharm by marking the directories as excluded in the project structure dialog.
0
Comment actions Permalink
It's sure nice to get over that hurdle with name spaces.

There are a lot of directories I would need to exclude. Is there a performance issue or other reason I should exclude unused packages.
0
Comment actions Permalink
Yes. Excluding the directories ensures that PyCharm will not index their contents and will not need to update indexes when the files there are changed.
0
Comment actions Permalink
Well I thought this was going well but most of my development environments are screwed up.

For example:

Development/JIRA
Development/tools
Development/utilities

The project title shows "Development [JIRA] (/Users/eduvall/ALMA/Development)" so this looks like my project for JIRA. However the project directory does not appear in the project tab, none of the files in the JIRA project are displayed in the project tab and PC warns that JIRA project is already open in project so I cannot add it. The files belonging to the JIRA project that are still open in the editor have lost all perks such as tab completion, bracket highlighting, etc.

I also lost my utilities project in PC. I now have two windows showing tools as the project.

In the tools project the Content directory is Development and the tools directory and files appear in the project tab.

In the JIRA project the Content directory is Development but I only see the files in Development. I don't see the JIRA project directory or files.

If I invalidate the caches in one window/project of PC do I loose all of my editing history in all projects?
0
Comment actions Permalink
If you have Development configured as a top-level project, you don't need to attach to it lower level projects (such as JIRA). What you need to do instead is mark the directories of those projects as source roots in Settings | Project Structure.
0
Comment actions Permalink
Thanks for the quick answers. I worked through this a lot this morning and did not seem to have a solution.

<verbatim>
Directory             Content root      Shows in JIRA project tool
Development/JIRA      Development       No (It should)
Development/tools     Development       Yes
Pycharm returns message stating two projects in window cannot have same content root.

If I exclude tools in JIRA project content then the library references to tools change to unresolved.

If in JIRA project I change content root to Development/tools pycharm returns message about not having intersecting content.

I created a project Development as you suggested. This seems to fix the inter-project library referencing and I see how to setup the servers to fit the various needs and I can open the one project in multiple windows though the window names are all the same except for the current file. So this is better than what I was dealing with.

With this arrangement will there be a problem or limitations with distributing projects separately such as Development/JIRA and Development/ASDM?

Thanks,
Gene


</verbatim>
0

Please sign in to leave a comment.