Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working dir setting in Preferences not respected #85

Open
ok97465 opened this issue Jul 8, 2023 · 6 comments
Open

Working dir setting in Preferences not respected #85

ok97465 opened this issue Jul 8, 2023 · 6 comments
Assignees
Labels
Milestone

Comments

@ok97465
Copy link

ok97465 commented Jul 8, 2023

Hello.

Thanks for letting me use your great program.

I'm using Spyder with the working directory set to the Project folder.

But In line_profiler, the working directory is set to the directory of the file being excuted.

In line_profiler how to change working directory option?

thanks.

@jitseniesen
Copy link
Member

Hello.

When running a file in Spyder, the working directory is normally set to the directory of the file being executed. This is true whether or not you use line_profiler.

If you want to use another directory as the working directory when running the script, you need to click on the menu item Run > Configuration per file ... (shortcut: Ctrl+F6). There you can pick the option "Run file with custom configuration" and use the "Working directory settings" at the bottom to select the working directory. The file will now be run with the working directory that you chose. If you then click on Run > Run line profiler, it should do what you want.

Let me know if this does not help.

@ok97465
Copy link
Author

ok97465 commented Jul 9, 2023

Thanks for quick reply.

이미지 2023  7  9  오전 9 17

My project structure looks like the picture above.
The executable file is located in the scripts folder and the file to be read are in the data folder.
The above code works fine because Spyder's working directory is set to the current working directory.

However, in Line_profiler, I get the following error.

이미지 2023  7  9  오전 9 22

@jitseniesen
Copy link
Member

Hmmm, thanks for the extra information, but it looks like something is different on your machine and mine, so I don't know at the moment ... 🤔

Can you help me find out what is happening?

  • What is your version of Spyder and spyder-line-profiler? One way to find the version of Spyder is to click on Help > About Spyder (in Spyder itself). To get the version of the plugin, use Help > Dependencies and scroll to the bottom.
  • In Spyder, go to Tools > Preferences and then click on Run in the left column. What options do you have selected? For me, it's "Execute in current console" and (Default working directory is) "The directory of the file being executed".
  • Open your file script1.py and select Run > Configuration per file. Is the option "Run file with default configuration" selected? If not, what options are selected?

I will be grateful for any information you can give me to help nail down this problem. There may be a bug in the plugin.

@ok97465
Copy link
Author

ok97465 commented Jul 9, 2023

  • Our dependences list is below:

Mandatory:

applaunchservices >=0.3.0 : 0.3.0 (OK)
atomicwrites >=1.2.0 : 1.4.0 (OK)
chardet >=2.0.0 : 4.0.0 (OK)
cloudpickle >=0.5.0 : 2.0.0 (OK)
cookiecutter >=1.6.0 : 1.7.3 (OK)
diff_match_patch >=20181111 : 20200713 (OK)
intervaltree >=3.0.2 : 3.1.0 (OK)
IPython >=7.31.1,<9.0.0,!=8.8.0,!=8.9.0,!=8.10.0,!=8.11.0,!=8.12.0,!=8.12.1 : 8.14.0 (OK)
jedi >=0.17.2,<0.19.0 : 0.18.1 (OK)
jellyfish >=0.7 : 0.9.0 (OK)
jsonschema >=3.2.0 : 4.17.3 (OK)
keyring >=17.0.0 : 23.4.0 (OK)
nbconvert >=4.0 : 6.5.4 (OK)
numpydoc >=0.6.0 : 1.5.0 (OK)
parso >=0.7.0,<0.9.0 : 0.8.3 (OK)
pexpect >=4.4.0 : 4.8.0 (OK)
pickleshare >=0.4 : 0.7.5 (OK)
psutil >=5.3 : 5.9.0 (OK)
pygments >=2.0 : 2.11.2 (OK)
pylint >=2.5.0,<3.0 : 2.16.2 (OK)
pylint_venv >=3.0.2 : 3.0.2 (OK)
pyls_spyder >=0.4.0 : 0.4.0 (OK)
pylsp >=1.7.2,<1.8.0 : 1.7.2 (OK)
pylsp_black >=1.2.0,<3.0.0 : 1.2.1 (OK)
qdarkstyle >=3.0.2,<3.2.0 : 3.0.2 (OK)
qstylizer >=0.2.2 : 0.2.2 (OK)
qtawesome >=1.2.1 : 1.2.2 (OK)
qtconsole >=5.4.2,<5.5.0 : 5.5.0.dev0 (OK)
qtpy >=2.1.0 : 2.2.0 (OK)
rtree >=0.9.7 : 1.0.1 (OK)
setuptools >=49.6.0 : 65.6.3 (OK)
sphinx >=0.6.6 : 5.0.2 (OK)
spyder_kernels >=2.4.3,<2.5.0 : 2.5.0.dev0 (OK)
textdistance >=4.2.0 : 4.2.1 (OK)
three_merge >=0.1.1 : 0.1.1 (OK)
watchdog >=0.10.3 : 2.1.6 (OK)
zmq >=22.1.0 : 23.2.0 (OK)

Optional:

cython >=0.21 : 0.29.33 (OK)
matplotlib >=3.0.0 : 3.7.0 (OK)
numpy >=1.7 : 1.23.5 (OK)
pandas >=1.1.1 : 1.5.3 (OK)
scipy >=0.17.0 : 1.10.0 (OK)
sympy >=0.7.3 : 1.11.1 (OK)

Spyder plugins:

spyder_line_profiler.spyder.plugin 0.3.2 : 0.3.2 (OK)

  • If working directory is set to "The directory of the file being executed", my example code is not working. my example code is able to run with "The current working directory."
  • I tried all options of Tools > Preferences > Run and Run > Configuration per file. But It was not working.

Thanks.

@jitseniesen
Copy link
Member

Thanks for the info. I tried it out and there is a bug in the line profiler plugin in that it does not pick up the setting in the Preferences when the working directory is set to "The current working directory", which is what you are doing. I will try to fix that.

However, I can work around the bug by using the same option in Run > Configuration per file. See the video below where I tried to reproduce your setting. You say that this does not work for you. So I still don't fully understand what's going on.

How do you run the script in the line profiler? Can you see anything that's different on your computer from the video?

lineprofissue

@ok97465
Copy link
Author

ok97465 commented Jul 22, 2023

Thank you for your efforts.

I usually set Preference->Run->The current working directory.

Run > Configuration per file didn't work when I took the previous screenshot, but it does now.

It's a bit odd, even for me.

@jitseniesen jitseniesen changed the title How to set working directory for line_profiler Working dir setting in Preferences not respected Jul 22, 2023
@jitseniesen jitseniesen self-assigned this Jul 22, 2023
@jitseniesen jitseniesen added this to the v0.3.3 milestone Jul 22, 2023
@jitseniesen jitseniesen modified the milestones: v0.3.3, v0.4.0 Jan 16, 2024
@jitseniesen jitseniesen modified the milestones: v0.4.0, v0.4.1 Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants