Python Forum
setting working directory in pycharm
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
setting working directory in pycharm
#4
I think you are mixing stuff together,what you do in first post is make a package.
(Dec-06-2018, 11:54 AM)saisankalpj Wrote: Is there any way to change the working directory in Pycharm itself,instead of code level,as I need the code to work through both cmd and pycharm
To make a folder that Python find wherever you in PyCharm or command line,
add that folder to sys.path(this is where Python search for .py files).

I find it easiest to not mess with PYTHONPATH for adding own folders permanently.
The site module offers a method that takes care of adding to sys.path without duplicates and .pth files.
Make a sitecustomize.py file in C:\Python37\Lib\site-packages or your site-packages folder.
# sitecustomize.py
import site

site.addsitedir(r'E:\div_code')
Test that it work.
C:\
λ ptpython
>>> import sys
>>> from pprint import pprint

>>> pprint(sys.path)
['C:\\python37\\Scripts\\ptpython.exe',
 'c:\\python37\\python37.zip',
 'c:\\python37\\DLLs',
 'c:\\python37\\lib',
 'c:\\python37',
 'c:\\python37\\lib\\site-packages',
 'E:\\div_code'] <----
For OS and Path look at Python 3.6/3.7 and pip installation under Windows

Now if a package(your first code) is placed eg in E:\div_code,then python will find it.
Reply


Messages In This Thread
RE: setting working directory in pycharm - by snippsat - Dec-06-2018, 01:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  working directory if using windows path-variable chitarup 2 790 Nov-28-2023, 11:36 PM
Last Post: chitarup
  Help setting up Pycharm & Remote Pi PickyBiker 3 2,031 Sep-17-2021, 04:04 PM
Last Post: PickyBiker
  Setup working directory in IDLE Pavel_47 3 3,862 Mar-06-2021, 08:59 AM
Last Post: Pavel_47
  [PyCharm] Working with virtual environment AndrzejB 1 2,184 Jul-18-2020, 06:22 PM
Last Post: AndrzejB
  CWD (Current working directory) pcsailor 5 4,758 Nov-11-2018, 10:14 AM
Last Post: Larz60+
  Configuring interpretor in PyCharm: [Errno 2] No such file or directory BoaCoder3 0 8,107 Sep-15-2018, 01:21 PM
Last Post: BoaCoder3
  how to save python file to working directory rpdohm 3 6,081 Sep-14-2017, 06:16 PM
Last Post: rpdohm

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020