I am struggling with our company's profile space which is limited to 250 MB for profile. I use PyCharm for some python project, but the problem is that PyCharm creates folder outside My Documents in:
C:\Users\Me\.PyCharmCE2017.3\
I would like to move the folder to some other location which is not synced with the server or to My Documents, where space is unlimited. Is there any way to change the location of the main Pycharm folder? I was looking for it in Pycharm settings but I couldn't find the option. Thanks!
Solution thanks to Rawing:
mklink /D "C:\Users\Me\.PyCharmCE2017.3" "C:\Folder\.PyCharmCE2017.3"
used from Windows command line. First you have to move original folder to your directory, here C:\Folder\ and then create a link with this command. No shared space problem anymore and Pycharm works perfectly fine! Thanks!
Related
When I do image processing in pycharm, I can't add images from my file explorer in the directory. How should I fix it?
I've done what I can as possible but I'm a starter of python. I wasn't able to solve this. So, I know this's not enough by myself.
Since you're using pycharm you must have created a project folder in a directory
That directory is located at C:\Users<user>\PycharmProjects if you have done default installation this will be visible in file explorer and you could use normal copy paste then
Recently, I'm unable to use relative paths in my code while using PyCharm. For instance, a simple open('test.txt', 'r') will not work - whereupon I am sure the file exists in the same level as the running py file. PyCharm will return this error.
FileNotFoundError: [Errno 2] No such file or directory:
After reading answers online on StackOverflow, I have tried multiple options including:
Changing test.txt to ./test.txt
Closing project, deleting the .idea folder, open the folder with code.
Reinstalling as well as installing the latest version of PyCharm.
Invalidating caches and restarting.
None of these options have worked for me. Is there someway I can tell PyCharm to refresh the current working directory (or even to see where it thinks the current working directory is)?
Edit: I should note that running the script in a terminal window will work. This appears to be a problem with PyCharm and not the script.
Change:
Run > Edit Configurations > Working directory,
which sets the working directory for a specific project. (This is on a Mac)
I have Pycharm 4.5, so things might have changed a bit.
Try going to Settings > Project > Project Structure
On this dialog, click your folder that has the source code in it, and then click the blue folder in the menu to note it as "source" folder. I believe this fixes a lot of the path issues in Pycharm
Here is the link to "content roots": https://www.jetbrains.com/pycharm/help/content-root.html
Current version 2019.2 somehow ignores "source root" from the "project structure". Here's how to actually enforce it:
Run -> Edit Configurations -> Python -> "Edit Templates" -> fill out "Working Directory"
__file__ refers to file path. So you can use the following to refer file in the same directory:
import os
dirpath = os.path.dirname(__file__)
filepath = os.path.join(dirpath, 'test.txt')
open(filepath, 'r')
In PyCharm, click on "run/edit configurations..."
Then find your script file in the "Python" dropdown menu. Check the "Working Directory" entry and change it if necessary.
EXACT ANSWER TO SOLVE THIS ISSUE ,,
GO TO EDIT CONFIGURATION (just LEFT side of GREEN CODE RUNNER ICON)
click on python (not any specific python script) ONLY SELECT PYTHON
then below right side click on [edit configuration templetes]
select current working dir by going into those blocks
It will change the CWD of all python file that exists in project folder..
then all file will understand the RELATIVE PATH that starts from your actual project name..
i hope this will resolve all your issue related path.
Sometimes it is different. I solved my problem by clicking "Run" at the Pycharm's toolbar and then "Edit Configurations..." and I change my Interpreter to another actual one. Just changing it in the settings does not help, but this opperation already does ;)
I too had the same issue few minutes ago...but,with the latest version of PyCharm it is resolved by simply using the relative path of that file..
For instance, a simple f = open('test', 'r') will work.
A little clarification for mac users. In mac, what #andere said above is correct for setting working directory. However, if your code is in a different folder, say working_dir/src/ (like classic java/scala file structure) in that case you still need to set your Sources Root. In mac's PyCharm this can be done by right clicking on the src/ folder > Mark Directory as > Sources Root. Helped me with lot of similar import issues. Hope this helps someone.
I have a PyCharm project on my Windows, where I am able to run most .py files by pressing Ctrl + Shift + F10 (or running the debugger). In one of the files however I get the error
Error running 'test':
Cannot run program "\opt\anaconda\bin\python" (in directory "..."): CreateProcess error=2, the system cannot find the file specified.`
The test.py file right now only contains print('hello')
I can do this for the other files, and using 'Execute selection in console' also works fine. Given I am on a Windows machine the "\opt\anaconda\bin\python" part looks suspicious, but I don't know how to fix it.
Any help?
Copying the content to another file (e.g. test_2.py) 'fixes' the problem, but since this is a collaborative project this isn't viable.
I think your case is cause by some project environment has changed.
I suggest your open the workspace.xml which located in .idea\, check the parameters in it.
or you can delete the directory ".idea" and re-create the project locate in the original path.
Hope it work
I had the same problem in PyCharm IDE and Windows after adding new libraries and some changes.
I recreated Run/Debug Configurations with these steps (Instead of recreating the whole of project!):
Select Edit Configurations... from top panel in PyCharm IDE
Select these files and press delete for deleting them
Recreate these files likes this images:
Click green arrow or press Ctrl + Shift + F10
This is what I had to do:
Check the .idea/workspace.xml for any old venv references (there are several tags like "SDK_HOME" which store the path to the venv) and update as necessary
Check the .idea/RunConfigurations for any run configs and update them (or delete and recreate as you like)
when I installed the pycharm I had the same issue. for this, you really need to understand the concept of the virtual environment. this error comes because you run the file in another directory in which you do not create any virtual environment.
let's say you create a virtual environment in any folder located at the desktop now you run the files in any other folder located in /user/AppData/any_folder then it will show the error that the system can't find the file specified.
So be sure you run in a file in the same folder in which you created a virtual environment.
I had the same problem after downloading a project from Github. It ended up being a configuration problem.
Creating a new project on Pycharm, pasting the code in it, and using your own configuration should solve the problem.
Recently, I'm unable to use relative paths in my code while using PyCharm. For instance, a simple open('test.txt', 'r') will not work - whereupon I am sure the file exists in the same level as the running py file. PyCharm will return this error.
FileNotFoundError: [Errno 2] No such file or directory:
After reading answers online on StackOverflow, I have tried multiple options including:
Changing test.txt to ./test.txt
Closing project, deleting the .idea folder, open the folder with code.
Reinstalling as well as installing the latest version of PyCharm.
Invalidating caches and restarting.
None of these options have worked for me. Is there someway I can tell PyCharm to refresh the current working directory (or even to see where it thinks the current working directory is)?
Edit: I should note that running the script in a terminal window will work. This appears to be a problem with PyCharm and not the script.
Change:
Run > Edit Configurations > Working directory,
which sets the working directory for a specific project. (This is on a Mac)
I have Pycharm 4.5, so things might have changed a bit.
Try going to Settings > Project > Project Structure
On this dialog, click your folder that has the source code in it, and then click the blue folder in the menu to note it as "source" folder. I believe this fixes a lot of the path issues in Pycharm
Here is the link to "content roots": https://www.jetbrains.com/pycharm/help/content-root.html
Current version 2019.2 somehow ignores "source root" from the "project structure". Here's how to actually enforce it:
Run -> Edit Configurations -> Python -> "Edit Templates" -> fill out "Working Directory"
__file__ refers to file path. So you can use the following to refer file in the same directory:
import os
dirpath = os.path.dirname(__file__)
filepath = os.path.join(dirpath, 'test.txt')
open(filepath, 'r')
In PyCharm, click on "run/edit configurations..."
Then find your script file in the "Python" dropdown menu. Check the "Working Directory" entry and change it if necessary.
EXACT ANSWER TO SOLVE THIS ISSUE ,,
GO TO EDIT CONFIGURATION (just LEFT side of GREEN CODE RUNNER ICON)
click on python (not any specific python script) ONLY SELECT PYTHON
then below right side click on [edit configuration templetes]
select current working dir by going into those blocks
It will change the CWD of all python file that exists in project folder..
then all file will understand the RELATIVE PATH that starts from your actual project name..
i hope this will resolve all your issue related path.
Sometimes it is different. I solved my problem by clicking "Run" at the Pycharm's toolbar and then "Edit Configurations..." and I change my Interpreter to another actual one. Just changing it in the settings does not help, but this opperation already does ;)
I too had the same issue few minutes ago...but,with the latest version of PyCharm it is resolved by simply using the relative path of that file..
For instance, a simple f = open('test', 'r') will work.
A little clarification for mac users. In mac, what #andere said above is correct for setting working directory. However, if your code is in a different folder, say working_dir/src/ (like classic java/scala file structure) in that case you still need to set your Sources Root. In mac's PyCharm this can be done by right clicking on the src/ folder > Mark Directory as > Sources Root. Helped me with lot of similar import issues. Hope this helps someone.
Does anyone know where or how to set the default path/directory on saving python scripts prior to running?
On a Mac it wants to save them in the top level ~/Documents directory. I would like to specify a real location. Any ideas?
On OS X, if you launch IDLE.app (by double-clicking or using open(1), for example), the default directory is hardwired to ~/Documents. If you want to change the default permanently, you'll need to edit the file idlemain.py within the IDLE.app application bundle; depending on which Python(s) you have installed, it will likely be in one of:
/Applications/MacPython 2.x/IDLE.app/Contents/Resources
/Applications/MacPython 2.x/IDLE.app/Contents/Resources
/Applications/MacPorts/Python 2.x/IDLE.app/Contents/Resources
/Applications/Python 2.x/IDLE.app/Contents/Resources
/Applications/Python 3.x/IDLE.app/Contents/Resources
Edit the line:
os.chdir(os.path.expanduser('~/Documents'))
On the other hand, if you start IDLE from the command line, for example, with:
$ cd /some/directory
$ /usr/local/bin/idle
IDLE will use that current directory as the default.
I actually just discovered the easiest answer, if you use the shortcut link labeled "IDLE (Python GUI)". This is in Windows Vista, so I don't know if it'll work in other OS's.
1) Right-click "Properties".
2) Select "Shortcut" tab.
3) In "Start In", write file path (e.g. "C:\Users...").
Let me know if this works!
In Windows 10+, click the Windows Start button, then type idle, and then right-click on the IDLE desktop app and open the file location. This should bring you to the Start Menu shortcuts for Python, and you'll find a shortcut to IDLE there. Right-click on the IDLE shortcut and select properties. Set the "Start in" directory to be where you want default save path to be.
It seems like you can get idle into the directory you want if you run any module from that directory.
I had previously tried opening idlemain.py through the path browser. I was able to open and edit the file, but it seemed like I wasn't able to save my modifications.
I'm just glad to hear other people are having this problem. I just thought I was being stupid.
If you open a module, that sets the default working directory.
Start IDLE.
File -> Open to open your file. And set the current working directory.
In my case, the default directory is set to the directory from which I launched IDLE. For instance, if I launched IDLE from a directory called 'tmp' in my home directory, the default save path is set to ~/tmp. So start your IDLE like this:
~/tmp $ idle
[...]
On Windows (Vista at least, which is what I'm looking at here), shortcut icons on the desktop have a "Start in" field where you can set the directory used as the current working directory when the program starts. Changing that works for me. Anything like that on the Mac? (Starting in the desired directory from the command line works, too.)
For OS X:
Open a new finder window,then head over to applications.
Locate your Python application. (For my mac,it's Python 3.5)
Double click on it.
Right click on the IDLE icon,show package contents.
Then go into the contents folder,then resources.
Now,this is the important part:
(Note: You must be the administrator or have the administrator's password for the below to work)
Right click on the idlemain.py,Get Info.
Scroll all the way down. Make sure under the Sharing & Permissions tab,your "name"(Me) is on it with the privilege as Read & Write.
If not click on the lock symbol and unlock it.
Then add/edit yourself to have the Read & Write privilege.
Lastly,as per Ned Deily's instructions,edit the line:
os.chdir(os.path.expanduser('~/Documents'))
with your desired path and then save the changes.
Upon restarting the Python IDLE,you should find that your default Save as path to be the path you've indicated.
I am using windows 7 and by going to Start-> IDLE(Python 3.6 32-bit)
The click on properties and then in the shortcut tab go to
Start in and entering the desired path worked for me kindly note if IDLE is open and running while you do this you'll have to shut it down and restart it for this to work
If you locate the idlelib directory in your Python install, it will have a few files with the .def extension. config-main.def has instructions on where to put the custom config files. However, looking through these I did not find any configurable paths (your install may vary). Looks like you might need to crack open the editor code to alter it.
If you are using linux, you can create simple .sh file as presented below::
#!/bin/sh
cd /fullPath/PythonScripts/
idle
make the file executable by right click-> properties-> permissions-> check the execute as program checkbox-> done
Run the file :)