Move Pycharm project to another directory - python

My home dir ran out of space and I wanted to move the PyCharm project to another directory. I ended up copying it because refactoring didn't work. I deleted the pycache and the zip exception, that had appeared was gone and now everything works as expected. I still use the venv location of my initial project location though, from what I can see in settings/python-interpreter.
Is there anything wrong with this procedure, anything I'm not aware of?
Should I edit some of the files in the .idea folder?
The $PROJECT_DIR$ variable caught my attention, but I couldn't find where this variable is actually set.

A clean way to move your project is right-clicking on your project folder in "Project view" (Alt +1 ) , choosing Refactor and then Move Directory.
The $PROJECT_DIR$ variable is dynamic and taken from the directory your project is in, so that isn't a problem
Your .idea folder should be recreated by PyCharm even if you completely delete it. However I wouldn't advise deleting your folder mainly because you will loose your project-level dictionary (wordlist).
Invalidating caches has a wider impact because it will clear IDE wide settings not just project specific settings. (It's mostly useful if your cache becomes outdated, which tends to manifest itself by inexplicable errors.)
If something goes wrong just open the moved directory as a new project going to File > Open. For a simple project there are 2 main settings that you should check and may have to adjust:
In settings "Settings" (Ctrl + Alt + S) go to Project: your_project_name and there check that Project Structure makes sense and retains your configurations.
In Run > Edit Configurations make sure that Script path and Working directory are set to the locations you want.
Is there anything wrong with this procedure, anything I'm not aware of?
From your description you took the right steps since refactor didn't work, just ensure the above configurations are met and if the IDE doesn't issue any errors you should be good.
Should I edit some of the files in the .idea folder?
This would rarely be necessary and is generally discouraged. The files in the .idea are IDE generated and should not be touched. Any necessary changes should be made using the IDE graphical interface to set configurations (which means you don't have to worry about the contents of .idea).

Related

Moving PyCharm projects folder and keeping reference to python interpreter

I'm using macOS 10.15.4 and PyCharm 2019.3.4
I currently have a folder inside the PyCharmProjects folder (that is automatically created when PyCharm first runs) where I keep projects for a class. I want to move this folder, which contains multiple other folders which each contain PyCharm projects, somewhere else on my computer (like the Desktop). The problem is if I move the folder (or even just a single PyCharm project) the next time I open the project in PyCharm, it says "Invalid python interpreter selected for the project." Now I can manually go into PyCharm preferences and point it to the new location I moved the folder so it can use the correct python interpreter. But this would be tedious to do for every single project I have. (And yes, every project I have uses its own interpreter and virtual environment.)
Is then a way I can move a folder containing multiple PyCharm projects without loosing the references to each of their respective python interpreters?
(Feel free to reword this question or the title.)
PyCharm uses configurations from your home directory. The docs say
macOS
Configuration
~/Library/Preferences/<PRODUCT><VERSION>
Caches
~/Library/Caches/<PRODUCT><VERSION>
Plugins
~/Library/Application Support/<PRODUCT><VERSION>
Logs
~/Library/Logs/<PRODUCT><VERSION>
where <PRODUCT> is PyCharm.
They are xml files. Among them also a list of configured interpreters. They are separate because they are available for all your projects to be chosen as the default interpreter. You'll have to edit the xml files.
For some reason PyCharm does not help with a moved virtualenv directory directly. (see comment from engineer: https://youtrack.jetbrains.com/issue/PY-32435#focus=Comments-27-3139072.0-0)
On the upside, everything else seems to work, except the path to the venv python. That one can be changed through preferences/project preferences/python interpreter. Just click on "add", "existing", and select the python compiler in your project folder.
Try not to select the ".virtualenvs" python compiler, as if you fumble like I did, it seems it's a bit of a pain to get rid of it and go back to the right one. If you do that, renaming the project folder once more gets you back to square one and you get to try again.
Note that I'm using MacOS. YMMV.

What do I need to do to get Django Unit Tests working again in PyCharm after renaming a project and its directory?

I have several projects open in one window, some of which are different branches of the same project. I decided to rename the directory and project for one of these branches in PyCharm using the Refactor option on the project. After doing so, the Django Unit Tests Run Configuration I had working no longer works. It is still trying to run the tests from the old directory name.
I have not found anywhere in the Run Configuration to specify the directory. The working directory, yes, but that doesn't fix it. I tried changing all instances of the old path to the new path in the workflow.xml file in the root project (which is where the Run Configuration was stored), but that didn't help, and may have messed up other configurations.
Does anyone know where to change the directory for Django tests in PyCharm?
The Django project root setting does not get updated when you use the Refactor / Rename option, so you'll have to update it yourself. Go to Preferences -> Languages & Frameworks -> Django. Select the project of interest. Just below the Enable Django Support checkbox is the Django project root: setting. Click the folder, navigate to your project root, and click Apply or OK.
(Note that while there are other questions with the same or similar answers, the questions being asked are different enough that neither Google searches nor SO searches found them, thus I chose to document the answer in a way that someone else can find the answer.)

What to commit to source control in Eclipse Pydev

I've create a pydev project in eclipse.
At the top level of my workspace I can see these two files:
.project
.pydevproject
I can also see these in each of my subfolders that contain my actual projects.
At the top of my workspace there is also a
.metadata. folder.
What should I commit to source control?
Ie what can I delete and still be able to open the project with minimal effort (hopefully entirely automated regeneration of files)? If this was Visual Studios C++ project the answer would be to keep just the ".sln", "vcxproj" and "vcxproj.filters" because the "vs" folder and "suo" files will autogenerate on openning. I've tried to delete the ".metadata" folder, but after that nothing appears to load in my workspace.
Also, I am working with someone not using an IDE. What eclipse files do we need to update to keep in sync?
Disclaimer: I am not familiar with PyDev, just with Eclipse in general. You definitely should not check in the .metadata folder. That one is for your Eclipse workspace as a whole and contains your personal configuration. (That's why your workspace appeared empty after you deleted that folder.) In fact, you should not check in your workspace folder at all, but just the several project folders within it.
Whether to check in the .project files is sort of a matter of taste. Those contain project specific information and settings and with those its easier to import the project into Eclipse, but you can import the project without those, too, it's just a bit more work. If other developers are not using Eclipse, those are useless for them. In the worst case, your co-developers will delete those files from source control and when you update your project later, they are deleted on your end, too, messing up your project.
About deleting the files: Note that there is a difference between not checking files into version control and deleting them locally. So in short: Do not commit those files into version control, but don't delete them locally, either. Depending on what sort of version control you are using, you can set it to ignore those files.

How to restore Pycharm Project in windows

I am having this extremely weird issue with restoring a pycharm project in pycharm 5 on windows. Originally all I wanted to do is make it so the project does not appear at the start selection, but ultimately that command has translated into something else.
So far I have checked my recycle bin and used recuva but it's no where to be found. Is there some type of default in the pycharm that disables this behavior and if it possible to get my projects back?
If you've cleared your recent projects you'll need to locate the folder where you saved your project.
Pycharm stores the individual project config files in a .idea directory in the project root, then further files for the general app config in Windows are stored in;
<User home>\.PyCharmXX\config that contains user-specific settings.
<User home>\.PyCharmXX\system that stores PyCharm data caches.
To open your project again, you'll need to point Pycharm's 'open project' dialog to the directory containing the .idea folder, so if you can't remember where you saved the project, I'd suggest running a search for .idea, remembering that it will likely be a hidden folder.
See the docs on the application data

Will Changing Home Directory Name Mess Up Virtual Environments?

I was going to change the home directory name on my MacBook, but I was wondering if that will mess up any virtual environments or any other files I'm not thinking of right now in my already created Python/Django projects?
The best way to find out is to set up a test, duplicate account with all the same setup (.login, .bashrc, .bash_profile, .tcshrc, etc.) and see what happens when you try.
You may be perfectly fine, or you might have your home directory name hard coded into one of those files, in which case testing this out first might show the problem really quickly (before you mess up your real home directory).
Rename the home directory, then create a link pointing the old directory name to the new directory name.
This way, anything that points to the old name will still work.

Categories