-
Notifications
You must be signed in to change notification settings - Fork 0
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
Linux vs Windows differences for __file__ (path to current/calling script file) #11
Comments
I have tried this suggestion: https://stackoverflow.com/a/44592299/5193830, but still doesn't work with Windows: filename = inspect.getframeinfo(inspect.currentframe()).filename
print('filename: ' + filename)
# filename: start_project.py
path = os.path.dirname(os.path.abspath(filename))
print('path: ' + path)
# path: C:\Users\vs66tavy\Downloads This suggestion also doesn't work as expected (https://stackoverflow.com/a/18489147/5193830): print('lambda trial ' + os.path.abspath(inspect.getsourcefile(lambda:0)))
# lambda trial C:\Users\vs66tavy\Downloads\start_project.py Also this suggestion didn't work (https://stackoverflow.com/a/2632297/5193830): os.path.dirname(str(__file__, encoding))
os.path.dirname(str(sys.executable, encoding)) I used Traceback (most recent call last):
File "start_project.py", line 101, in <module>
print('Test 1: ' + os.path.dirname(str(__file__, encoding)))
TypeError: decoding str is not supported os.path.dirname(sys.executable) # returns
# C:\Python38
|
Using
I can work with that. Thanks to @RRemelgado for pointing out that If this becomes again an issue (possibly when addressing #9 and using argparse ), the check also this option https://stackoverflow.com/a/51724506/5193830: display_images_py_file = pkgutil.get_data(__package__, "src/display_images.py") |
It looks like
__file__
&os.path.realpath(__file__)
returns different things depending on the OS (Windows vs Linux).On Windows:
On Linux:
On Windows,
os.path.realpath(__file__)
returns the path to the Excel file that is used as the argument forstart_project.py
and not the path to the executed script.On Linux, this behaves as expected - it returns the path to the executed script and not to the Excel file. No error is therefore given under Linux and the tool works as expected.
Python versions:
Need to fix this.
The text was updated successfully, but these errors were encountered: