2

I am trying to learn Python coming from R. I am used to the Project functionality provided by RStudio, that I can create a new Project and start a new session loading the file with '.Rproj'. The new session automatically uses the folder as the working directory and then I can set all the paths relatively. No need to change anything for different computers etc.

I tried asking people more familiar with python but usually nobody really understood my question. I heard, this would not be a problem once i started using jupyter or other stuff correctly when I were to use my files on another session.

My questions is then either if there is something like the Project functionality from RStudio or how do I better manage my projects across different computer. I could not any good links on that.

Phil
  • 7,287
  • 3
  • 36
  • 66
Max M
  • 806
  • 14
  • 29

2 Answers2

3

I am not so much familiar with R studio, but the functionality that you described are available on spyder IDE. You have dedicated project window and you and switch between project. There are many more functionalities (lie an always-on python console, variable/function display). Please check https://www.spyder-ide.org/ You can further use the python os package to make your code os independent.

Vinod Kumar
  • 1,383
  • 1
  • 12
  • 26
3

I have the same issue. Though the main thing I use RStudio Projects for is to manage the working directory, and open RStudio in the right place. The best I've come up with is very specific to my problem - it doesn't do any of the other stuff .rproj and RStudio do, and isn't terribly portable.

I'm on Windows, using anaconda and JupyterLab in (it's not quite RStudio, but seems a good option to me) and I've found it a pain to navigate to the right location with the right environment for each project.

My understanding of python isn't great, but it looks like with jupyter lab .ipynb files the default working directory is the directory the file is in (so doesn't suffer from the chronic setwd() issue that .rproj helps to eliminate).

So I've created a .bat file (called pyproj.bat in this case) in the root of my project folder structure, to open jupyterlab in the right python environment:

call <anaconda_dir>/Scripts/activate.bat
call conda activate <project_environment_name>
call jupyter lab
cmd /k

My first line of that script is call %USERPROFILE%/Anaconda3/Scripts/activate.bat which at least gives it a chance of being portable between users in my organisation.

Would be nice if there were something a bit more automatic that could handle this - e.g. better searching for the activate script, and perhaps the environment management too (perhaps write the .yml and offer to build the environment if it's not present)

(Borrowed some the .bat idea from this question: How to make batch files run in anaconda prompt)

s_pike
  • 1,710
  • 1
  • 10
  • 22