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.
Related
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).
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.
When installed and then opened, both platforms create the following folders in the %UserProfile% directory...
(e.g.: "C:\Users\[username]):
".spyder-py3"
".anaconda"
".conda"
".config"
".ipython"
".matplotlib"
I've got my working folder in, say, the following path: "B:\Python". I want to have the aforementioned folders stored in said path, and the Anaconda and Spyder platforms to still be able to find them. Where do I modify the paths from the default one (user profile) to the new one ("B:\Python")?
(Spyder maintainer here) No, there isn't, sorry.
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.)
I'm reading headfirst python and have just completed the section where I created a module for printing nested list items, I've created the code and the setup file and placed them in a file labeled "Nester" that is sitting on my desktop. The book is now asking for me to install this module onto my local copy of Python. The thing is, in the example he is using the mac terminal, and I'm on windows. I tried to google it but I'm still a novice and a lot of the explanations just go over my head. Can someone give me clear thorough guide?.
On Windows systems, third-party modules (single files containing one or more functions or classes) and third-party packages (a folder [a.k.a. directory] that contains more than one module (and sometimes other folders/directories) are usually kept in one of two places: c:\\Program Files\\Python\\Lib\\site-packages\\ and c:\\Users\\[you]\\AppData\\Roaming\\Python\\.
The location in Program Files is usually not accessible to normal users, so when PIP installs new modules/packages on Windows it places them in the user-accessible folder in the Users location indicated above. You have direct access to that, though by default the AppData folder is "hidden"--not displayed in the File Explorer list unless you set FE to show hidden items (which is a good thing to do anyway, IMHO). You can put the module you're working on in the AppData\\Roaming\\Python\\ folder.
You still need to make sure the folder you put it in is in the PATH environment variable. PATH is a string that tells Windows (and Python) where to look for needed files, in this case the module you're working on. Google "set windows path" to find how to check and set your path variable, then just go ahead and put your module in a folder that's listed in your path.
Of course, since you can add any folder/directory you want to PATH, you could put your module anywhere you wanted--including leaving it on the Desktop--as long as the location is included in PATH. You could, for instance, have a folder such as Documents\\Programming\\Python\\Lib to put your personal modules in, and use Documents\\Programming\\Python\\Source for your Python programs. You'd just need to include those in the PATH variable.
FYI: Personally, I don't like the way python is (by default) installed on Windows (because I don't have easy access to c:\\Program Files), so I installed Python in a folder off the drive root: c:\Python36. In this way, I have direct access to the \\Lib\\site-packages\\ folder.