I've been testing out PyCharm but ran into a crazy little feature and or bug and cannot figure out how to solve it.
I've created a project on a network, and created a project locally and added a network folder to the project both are resulting in the same bizarre behavior.
I can open files, navigate the project tree and everything is fine inside of PyCharm. But once I switch focus to another window and then come back to PyCharm, it will automatically close the entire project tree back to the root and close any files I have had open.
This is certainly making PyCharm completely unusable. I've been searching most of the morning to find out how to stop this but haven't even come across any other similar problems.
To test, I made a sample Python directory on the network, filled it with a few folders to simulate modules and added init.py files to them all. Then created a PyCharm project in the folder. It will exhibit this behavior and I can't figure out how to stop it from closing everything. What's going on?
This is Windows Community PyCharm 2017.2.1 Version. A picture would just be everything open and then everything closed and the tree view, since it closes everything when it regains focus. I'm not sure how I'd best take a picture of that.
There is an open bug filed in PyCharm for this issue which is yet to be fixed : https://youtrack.jetbrains.com/issue/IDEA-171352
Description of the bug mentions :
I didn't observe the problem with PyCharm 2016.3.3.
PY-171.3780.115, JRE 1.8.0_112-release-736-b13x64 JetBrains s.r.o, OS
Windows 10(amd64) v10.0 , screens 2560x1440, 1920x1080, 1080x1920
Apparently the issue is in later releases of PyCharm
Related
Issue
So, I've used PyCharm for quite a while and I know how to set environments, etc. For some reason, I can't seem to access the Python interpreters that I've got (see image).
When I open the same project in Clion I am able to run the files and I can see the interpreters.
Attempted solutions
Run in Clion to see if the interpreter "sticks".
Removed the .idea file.
Reinstalled PyCharm.
Usually Python Interpreter is a sub-item of Build, Execution, Deployment in the Settings. (In PyCharm 2021, the layout in PyCharm 2019 was slightly different).
The fact the item appears separately is a strong hint that you either installed a plugin or for some reason the IDE was opened in LigthEdit mode (this can easily happen if you launch the IDE using the command-line). This can also happen if you don't have an open project (having files open is not the same as opening a project, as such, with an .idea folder - the IDE configuration files will be different.)
Having the IDE in LightEdit mode provides only a limited set of functionalities, so the IDE doesn't allow you to configure an Interpreter in the usual way (other setting dialogues will also behave different from usual).
The solution is to Exit the LightEdit mode, opening your previous project or a new one by going to File > Open or File > New Project.
I am trying to learn Python coming from R. I am used to the Project functionality provided by RStudio, that I can create a new Project and start a new session loading the file with '.Rproj'. The new session automatically uses the folder as the working directory and then I can set all the paths relatively. No need to change anything for different computers etc.
I tried asking people more familiar with python but usually nobody really understood my question. I heard, this would not be a problem once i started using jupyter or other stuff correctly when I were to use my files on another session.
My questions is then either if there is something like the Project functionality from RStudio or how do I better manage my projects across different computer. I could not any good links on that.
I am not so much familiar with R studio, but the functionality that you described are available on spyder IDE. You have dedicated project window and you and switch between project. There are many more functionalities (lie an always-on python console, variable/function display).
Please check
https://www.spyder-ide.org/
You can further use the python os package to make your code os independent.
I have the same issue. Though the main thing I use RStudio Projects for is to manage the working directory, and open RStudio in the right place. The best I've come up with is very specific to my problem - it doesn't do any of the other stuff .rproj and RStudio do, and isn't terribly portable.
I'm on Windows, using anaconda and JupyterLab in (it's not quite RStudio, but seems a good option to me) and I've found it a pain to navigate to the right location with the right environment for each project.
My understanding of python isn't great, but it looks like with jupyter lab .ipynb files the default working directory is the directory the file is in (so doesn't suffer from the chronic setwd() issue that .rproj helps to eliminate).
So I've created a .bat file (called pyproj.bat in this case) in the root of my project folder structure, to open jupyterlab in the right python environment:
call <anaconda_dir>/Scripts/activate.bat
call conda activate <project_environment_name>
call jupyter lab
cmd /k
My first line of that script is call %USERPROFILE%/Anaconda3/Scripts/activate.bat which at least gives it a chance of being portable between users in my organisation.
Would be nice if there were something a bit more automatic that could handle this - e.g. better searching for the activate script, and perhaps the environment management too (perhaps write the .yml and offer to build the environment if it's not present)
(Borrowed some the .bat idea from this question: How to make batch files run in anaconda prompt)
I am using PyCharm Community Edition and tried versions 2019.1.3 and 2019.1.2. I can create a new project and files to that project but as soon as I write anything (e.g: in a .py file, in a .html file or even entering the script path when adding a configuration) it crashes (also crashes when trying to edit an already existing project). Any suggestions what I can do to fix that?
Go to Preferences/Appearance and select a different font, I used "Monospace" and things seem to work again.
On my system, PyCharm was crashing when it called into CoreText rendering. Reinstalling and trashing preferences otherwise didn't work.
Even after looking through numerous topics about this matter, I have been unable to find a solution for my predicament.
I have recently downloaded Anaconda navigator v.1.7.0 from which I can use Spyder v3.2.6 has an IDE. I would like to open .py scripts from file explorer with Spyder has default, but when I go in ‘open with’ and click on spyder.exe in C:\Anaconda\Scripts, all I get is a black console window that closes instantaneously. Can anybody help me out on this matter?
I note that I can drag and drop .py files on the Spyder console directly, but has previously mentioned by other users, this feels a little awkward and cumbersome.
From How to get Spyder to open python scripts (.py files) directly from Widows Explorer, I have tried manipulating the spyder-script.py in regedit but to no avail.
This is a similar issue but doesn’t seem pertinent for the current case: WinPython Cannot run .py files directly (without spyder)
These two threads precisely discuss about what I’m trying to do:
How to read a .py file after I install Anaconda? But no good answer
Set Spyder as default Python and there are comments that talk about creating a spyder.dat file, but I have no idea on how to do this and I can’t find any proper documentation on it.
I also took a look at this: https://github.com/spyder-ide/spyder/issues/466 and this https://github.com/spyder-ide/spyder/issues/971 but I can’t make sense of the exchanges
Could the answer be with the spyder.dat file? Or maybe with something else? That's what I'd like to know.
Cheers
This issue has come up with previous versions of PyCharm (see this SO post and this one), but it manifests somewhat differently in 4.5.
I am trying to add another library to the Python path of my current project. This is an internal library and consists of a bunch of .py files in a different directory from the current project. I carry out the following steps:
Go to File -> Settings -> Project: summary -> Project Interpreter
Click on the gear icon near the top right corner of the screen that appears in the dialog
Select More... from the context menu that pops up
Click on the interpreter I am using
Click on the last of the 4 icons to the right of that, the thing with a folder and arrows, with tooltip "Show paths for the selected interpreter"
Push + in the resulting popup
Use the file dialog to add the path of the library
Having done this, the result is:
Good:
Running the current project code from a Run Configuration works; that is, the external library is picked up in the PYTHONPATH
The added path does not immediately disappear from the interpreter path dialog, as it was doing in 4.0 (see comment to this answer in one of the SO posts mentioned above).
Bad:
Indexing of the new library fails, and all references to the external library are marked as unresolved references in the editor
I have even tried File -> Invalidate Caches / Restart... and pressed the Invalidate and Restart button that appears. After sitting and waiting for indexing to finish, I get the same result. I have been very careful with setting the right path, and it seems to be correct, given that running the code actually works.
Does anyone know of a workaround for this issue, short of adding the external code as a content root?
I ran into a very similar issue. I am working on an OpenStack component, and all third-party libraries were getting marked as unresolved references. It turned out to be because the .tox directory is automatically excluded by PyCharm, which prevents any virtual environments in that directory from getting indexed properly.
To fix this, I went to the Editor > File Types dialog of the Preferences menu, and removed the .tox folder from the Ignore files and folders option.
Checked w/ JetBrains support, they confirmed that the only ways to add external libraries to a PyCharm project are:
Add the library as a Content Root
OR
Open it as separate project in the same window and attach it to your current project
Not the cleanest approaches, as they both basically mean adding the other library's actual code to your project. But they are the only ones at this point.