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

AttributeError: 'str' object has no attribute 'suffix' #784

Closed
psykokwak-com opened this issue Feb 25, 2024 · 5 comments · Fixed by #785
Closed

AttributeError: 'str' object has no attribute 'suffix' #784

psykokwak-com opened this issue Feb 25, 2024 · 5 comments · Fixed by #785

Comments

@psykokwak-com
Copy link

Describe the bug
I just installed scalene with the following :
(venv) C:\Users\Jyce\Desktop\test>python -m pip install -U scalene

Then execute :
(venv) C:\Users\Jyce\Desktop\test>python -m scalene run.py

Here What I got :

Scalene failed to initialize.
Traceback (most recent call last):
File "C:\Users\Jyce\Desktop\test\venv\lib\site-packages\scalene\scalene_profiler.py", line 2006, in run_profiler
profiler = Scalene(args, Filename(prog_name))
File "C:\Users\Jyce\Desktop\test\venv\lib\site-packages\scalene\scalene_profiler.py", line 707, in init
Scalene.__orig_python = redirect_python(preface, cmdline, Scalene.__python_alias_dir)
File "C:\Users\Jyce\Desktop\test\venv\lib\site-packages\scalene\redirect_python.py", line 47, in redirect_python
if sys.platform == "win32" and sys.executable.suffix == ".exe":
AttributeError: 'str' object has no attribute 'suffix'

Desktop (please complete the following information):

  • OS: Windows 11 Pro
  • Python : 3.10.6

If you have not yet tried with the repository version (python3 -m pip install git+https://github.com/plasma-umass/scalene), please try that before reporting.
=> Tried and I got the same error.

@FSaal
Copy link

FSaal commented Feb 26, 2024

I am getting the same error using python 3.11.5.
Removing str( from line 46 in redirect_python.py fixed this.
I don't know if redirect_python must return a str instead of a Path, if not, reverting the changes from commit #769 in redirect_python.exe would fix this issue.

@LucasRr
Copy link

LucasRr commented Feb 26, 2024

Getting the same issue here. Indeed, removing str() from l. 46 of redirect_python.py as FSaal suggested solved the issue.

@emeryberger
Copy link
Member

Thanks for the report. I'm waiting for the PR to go through CI. Once it does, I'll merge it and you should be able to verify that it works by installing from the repo (python3 -m pip install git+https://github.com/plasma-umass/scalene). Please report back!

@emeryberger
Copy link
Member

Tagging @alphabetagamer

@alphabetagamer
Copy link

alphabetagamer commented Mar 7, 2024

Ideally, no module should modify system variables, if we are using methods for a different type we can modify a copy of it. Updating the latest commit with this thought in mind, let me know if it aligns with the repository guidelines.

Also I can see in test it is being asserted that the variable should be modified and then reinstated which is not the case in redirect_python.py

assert sys.executable != original_sys_executable
sys.executable = original_sys_executable

Also in redirect_python.py sys.executable being a Path object is only useful for using .with_suffix and .suffix commands which can easily be swapped with string equivalents. Does sys.executable being a path variable play any role elsewhere in the code? In my cursory glance that was not the case. I have updated the latest PR with suggested changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants