Pydev in Eclipse default working directory - python

What is the default working directory for my project? I have several projects under my workspace, and a couple of run configurations. I use os.getcwd() and the directory goes to other project's folder, after deleting all run configurations, the directory goes to eclipse's install folder. How to make the default working directory goes to my project folder or the \src folder?
EDIT:
In my PYTHONPATH that will be used in the run:
C:\Program Files\eclipse\dropins\plugins\org.python.pydev_1.5.4.2010011921\PySrc\pydev_sitecustomize;
C:\(MyProjectDirecotry)\\src;
C:\Python26;
C:\Python26\DLLs;
C:\Python26\lib;
C:\Python26\lib\lib-tk;
C:\Python26\lib\plat-win;
C:\Python26\lib\site-packages
maybe there's C:\Program Files\eclipse\dropins\plugins\org.python.pydev_1.5.4.2010011921\PySrc\pydev_sitecustomize; in the first line causing the issue. Why is this happened? How to revert it back to default? Thanks.

Open Run Dialog...-> Select your run configuration->Arguments Tab->Working directory:
mine is set to ${workspace_loc}:test/src/ for a project name test i created in my workspace

Related

Setting working directory in PyCham doesn't seem to work

I keep running into path issues in my flask app, when running in PyCharm. I've set the working directory in my run configuration to project-root/api/src, but the relative paths to resources don't resolve properly.
To check what's going on I ran os.getcwd() and I'm getting project-root.
What am I doing wrong? I tested the same project with a colleague with a identical (to my knowledge) configuration and on his machine os.getcwd() properly returns what is expected, project-root/api/src.
I tried reconfiguring the project from scratch, by removing .idea folder and creating the project again in PyCharm, to no avail.
I'm using macOs BigSur, Python 3.9 and PyCharm 2021.2.1.
Screenshot below contains my configuration (sensitive info, like company/project name removed):
I managed to solve this issue myself - the reason was that I'm using pipenv, which requires a .env file to be present in the root of the project folder. Flask, when finding such a file, switches the working directory to the root project folder, disregarding any PyCharm setting.
A solution to this is to add a FLASK_SKIP_DOTENV=1 to the application environment variables.
Described in detail here: https://github.com/pallets/flask/issues/3209

working directory changes to /tmp/ when python script runs with mlflow

I have a strange issue with python working directory when running with mlflow run -e build .
The script running successfully locally/using IDE, but when running it with mlflow the problem is that the working directory changes to /tmp folders instead of the correct working directory where the script resides (I have some path dependencies that certain folders should be present in ./* so thats why my process fails.
I had a feeling that something with the working directory messed up so I did os.getcwd() prints and saw the issue with temp folders.
I had a similar project that I configured in a similar manner before and didn't have these issues.
any idea what might be the issue?
I think this is the default behavior based on the documentation
By default, MLflow uses a new, temporary working directory for Git projects. This means that you should generally pass any file arguments to MLflow project using absolute, not relative, paths. If your project declares its parameters, MLflow automatically makes paths absolute for parameters of type path.
Maybe you need to specify the path through the MLproject-file but I am afraid I have not used it to give you any further help, as I had used mlflow with databricks.

Path terminal rollback to previous on VSCode after run code

I'm using VSCode and Anaconda for virtual envs.
On a new folder (for a new project), I navigate to the folder of the project on VSCode terminal and activated the correct env for that project.
When I run any code from this folder, the terminal comeback to the folder it was previously, and I need to "cd" to the correct folder again.
I don't know if it is a VSCode configuration or an Anaconda.
What do I need to configure to keep the path after running the code?

PyCharm won't create configuration to run

For the last 2 days PyCharm won't create the configuration setting to run my Python files and I have to create them manually to run my codes.
Before that PyCharm created those configuration setting for me, and all I had to do was just press Shift+F10.
Any ideas?
If you're using Linux or Mac, I've seen a similar (not the same) issue where the app (in this case PyCharm) was installed with root user via sudo and then the executed as normal user, that then won't have permissions to create/change the configuration files, which in PyCharm's case is the .idea folder in your project folder.
If this was previously working, maybe an update to PyCharm while you were running as root may cause the same issue (folder root becomes the owner of the folder and normal user can't change it).

Directory change not occuring with setvirtualenvproject

I'm embracing VirtualEnvWrapper - and like what I see a lot. However as I try to get going I'm not seeing the behaviour I expect when trying to set up project directory association with virtual envs.
I've installed virtualenv and -wrapper. I can create envs and "workon" lists them fine. I can deactivate and rm them happily. So all appears functional. I read the docs regarding project mgmt. (Also a good video tutorial, and the desired proj association behaviour explained at 10:39 )
When I try to associate a work directory with an env, it accepts my cmds fine, but when I "workon" the project, it does not put me into my designated working directory.
e.g. I have a working area ~/Ross_code (and I've set this in my .bashrc as $PROJECT_HOME). In there is an existing project folder ~/Ross_code/superproj
So now I create an env with
mkvirtualenv superp
Then I go to my existing project dir and associate it with the env:
cd ~/Ross_code/superproj
setvirtualenvproject
Setting project for superp to /Users/ross/Ross_code/superproj
Then I exited the virtual env with "deactivate" and reactivated with
workon superp
But the present working dir remains my ~/ folder.
I checked the .project file which seems to have been set properly by the call to setvirtualenvproject:
cdvirtualenv
more .project
/Users/ross/Ross_Code/superproj
but calling "workon" never sticks me into the expected spot. I thought maybe the env and the project directory needed to be of the same name, but that didn't make any difference either.
Any idea why that very attractive project association capability doesn't work for me?
-Ross.
LATER - More info:
I tried to also use the mkproject command, which should create a directory for my code in the $PROJECT_HOME area, and create the virtualenv at the same time and associate them with each other.
Calling
mkproject junkproj
does in fact create the project directory nicely, and sticks me into the virtualenv, and cd's into the junkproj directory. But when I deactivate, and then "workon junkproj" again, I'm still left in my ~/ directory, rather than going into the project directory in $PROJECT_HOME
:(
The problem here is that the newer versions (this hit me upgrading from ubuntu 14.04 to 16.04) of virtualenvwrapper use a slightly different protocol for the setvirtualenvproject parameters:
setvirtualenvproject [virtualenv_path project_path]
In order to make the association you want in any virtual env, be in the project folder and the virtualenv and use:
setvirtualenvproject $VIRTUAL_ENV .
The dot is for the present directory - or you can use the path of the directory you want workon to take you to. Once you do this workon will switch you to the folder you want and cdproject will work as expected.
If you used the old protocol, you'll have a .project file in your project folder - you can move this to the $VIRTUAL_ENV folder rather than invoking the command with the new protocol to make the association. The file just contains the project directory you want to associate with virtualenvwrapper shortcut commands like workon and cdproject.
workon doesn't auto change directory to project or environment directory.
You can do this with the postactivate script - there's a really quick how-to in the second half of the virtualenvwrapper tips and tricks section.

Categories