Closed JosephLoustau closed 7 months ago
There are two parts in that issue.
Pycharm runs the script from the script itself while VScode does it from the opened directory by default. So using the function os.get_cwd()
gives 2 different results:
Pycharm : user_path_to_reho\REHO_tools\REHO\scripts\examples
VScode : user_path_to_reho\REHO_tools\REHO\
So when later on the function os.path.realpath(path_given)
is used, we obtain:
Pycharm : user_path_to_reho\REHO_tools\REHO\scripts\template\data\buildings.csv
VScode : user_path_to_reho\REHO_tools\template\data\buildings.csv
This can be corrected by changing the settings of VScode python.terminal.executeInFileDir
. It can be done by:
"python.terminal.executeInFileDir": true
in the settings.json file. :warning: This should be properly added to the documentation
Now, with the current directory set to the script, we are not able to import reho
as it does not belong to the path.
The reason why it still works in Pycharm is that it automatically adds to the sys.path
the opened directory and so the same should be done but manually in VScode.
The workaround is to add in the settings.json the path to the environment:
Windows : Ctrl + Shift + P > open settings > click on Preferences: Open User Settings (JSON) > write:
"terminal.integrated.env.windows": {"PYTHONPATH": "${workspaceFolder}"}
Mac : F1 > open settings > click on Preferences: Open User Settings (JSON) > write:
"terminal.integrated.env.osx": {"PYTHONPATH": "${workspaceFolder}"}
If you have not done it before, add in the settings the line:
"python.terminal.executeInFileDir": true
The final file should look like this:
{
"python.defaultInterpreterPath": "user_path_to_python\\python3.10.exe",
"[python]": {
"editor.formatOnType": true
},
"git.openRepositoryInParentFolders": "always",
"hediet.vscode-drawio.resizeImages": null,
"hediet.vscode-drawio.codeLinkActivated": false,
"hediet.vscode-drawio.theme": "atlas",
"svg.preview.mode": "svg",
"terminal.integrated.env.windows": {"PYTHONPATH": "${workspaceFolder}"},
"python.terminal.executeInFileDir": true,
}
Hi. I also have this same issue when working in the terminal. I have placed my .env
file in a folder, and now wish to run the test run.py
script which I downloaded from the repository using
wget https://github.com/IPESE/REHO/raw/main/scripts/template/run.py
My folder looks like this:
my_folder
- .env
- run.py
Expected behaviour would be for the following to work:
$ cd my_folder
$ python run.py
But I also get the error involving .env.
Does the problem still remain after this commit https://github.com/IPESE/REHO/commit/4a63b03aec4f85ae097582e4bd1ab2c3b5d03e0c ?
@DorsanL Yes, this problem remains. I thought it was due to the Cloud license in #34, but I believe it is this issue rearing its head again.
If I install REHO (e.g. pip install REHO
), create a .env
file in my local working folder and then run the test reho-test-import
, I still get the error Exception: AMPL_PATH is not defined. Please include a .env file at the project root (e.g., AMPL_PATH='C:/AMPL')
. Except now, I do not have a project root. I just have a working folder which could be anywhere on my file system. It seems that REHO is making assumptions about where the .env
file should go, but this is incompatible with a pip install
(which places the package in an arbitrary location on my computer).
This should no longer be a problem after the changes here: https://github.com/IPESE/REHO/commit/b0ba53c1118e49b7a52d66655314b7280491da82
To sum up:
reho/
directory) or at the current working directory (i.e., where the script is run)
Is there an existing issue for this?
What happened?
It seems the relative path are not working as expected in VS code
Version
1.0.2 (Stable)
Relevant log output
No response
Anything else?
No response