Can't see/edit my own External Libraries anymore
Until today, my Django project was showing up correctly within PyCharm - including two of my own libraries that I installed through pip -e (that is, they are installed in the virtualenv together with their source code). Both of those libraries would should up under the “External Libraries” folder, in the Project window.
I had to reconfigure this project, and now I can't for the life of me make those same libraries visible/editable anymore. PyCharm is even complaining that their “import” statement is an error ("No module named xxx"), but it still runs properly!
What am I missing? The Python interpreter is correct, I'm using my own virtualenv installation, everything works outside (and inside!) PyCharm, only I can't see/edit my libraries.
Using PyCharm 2024.1.4, on Mac OS Sonoma, with Python 3.12 installed from HomeBrew.
Thanks,
Rubens
请先登录再写评论。
Might be related to https://youtrack.jetbrains.com/issue/PY-57566/Support-PEP-660-editable-installs.
Could you please clarify how packages were installed (setup.py or pyproject.toml)? Any extra information about the project and interpreter setup would be highly appretiated.
Hey Daniil,
Thanks for the link, it seems to be related to my problem, indeed. In my case, I'm installng it with pip from my own GitHub repo, but the end result is the same, I suppose it's also related to the way setuptools work. I do something like:
and inside the required packages file I have:
As to my environment, I use the separate virtualenv tool (not the native Python 3 venv).
For the record, in my case things still worked from the command line, so the problem is definitely just within PyCharm, not a general installation problem.
I found a different workaround: if I recreate the PyCharm project adding the PARENT folder as my “Django Project folder”, (e.g.: myvirtualenv/ instead of myvirtualenv/mydjangoproject/), then at least PyCharm stops complaining about my imports, and I can again click on a keyword and land within the library, debug, etc. The only thing that still doesn't work as before is having my libraries listed under “External Libraries”. But since I added the parent folder, I can now see them, browse them, open in PyCharm, etc.
I will try the workaround suggested by Adam Forster, that is, to install my libraries using:
Maybe that solves my problem too!
Thanks,
Rubens
Sure - I install Python with Homebrew, and https://pypi.org/project/virtualenv/ and https://pypi.org/project/virtualenvwrapper/ with pip, on the “Mac OS” level. Then I create my virtual envirnoments using virtualenv/virtualnvwrapper. As mentioned before, my own libraries I install with pip again (using -e to clone the source code), and THEN I setup PyCharm to work on all that.
That's how I've always done, for years. Recently I had to re-do it again, using the latest version of PyCharm, and what I wrote in my original post started to happen…
Sorry for the late reply. I've recreated a similar environment with homebrew Python3.12 and virtualenvwrapper, but I've had no luck reproducing the problem.
Please try upgrading to the latest, resetting IDE caches by doing File | Invalidate Caches with all options toggled and check if the issue persists afterward.
Also, just so you know, library files are protected from unwanted editing, and you will be prompted to lift read-only mode when you start editing.
Hey Daniil,
Thanks for keeping trying! But still no success.
I removed all data from my previous project (.idea folder, etc.), and opened my Django project again, from within PyCharm. It set everything automatically correctly: Python interpreter, DB connection, etc. I can run the project from the PyCharm runner/debugger, all good.
But, again - my already-downloaded dependencies, which ARE being used by the Django project, appear in PyCharm with the “red snake underline” ("unresolved reference"), and sure enough, I cannot CMD-click on them to open the files in the editor ("cannot find declaration to go to"). So they “work”, but PyCharm doesn't acknowledge them as part of my source files.
Under the “External Libraries” section of PyCharm, my libraries are listed within site-packages as any other dependency, that is, the .dist.info folder. All correct, except… PyCharm cannot find the already-downloaded sources (which are in the virtualenv/src folder as usual).
Did you do any manual configuration in your tests, to make the downloaded source libraries visible/editable? Did PyCharm “automatically find” them in your virtualenv? I didn't get the message you mentioned, about libraries being read-only. It simply looks like PyCharm cannot “figure out” I'm using downloaded libraries…
The issue seems more profound than we expected, and I'm still struggling to reproduce it.
Could you please create a bug report in the PyCharm branch of YouTrack: https://youtrack.jetbrains.com/issues/PY so we can properly process it?
https://youtrack.jetbrains.com/issue/PY-57566/Support-PEP-660-editable-installs is open since 2022 but nothing happened so far