Determining application path in a Python EXE generated by pyInstaller
I found a solution. You need to check if the application is running as a script or as a frozen exe:
import os
import sys
config_name = 'myapp.cfg'
# determine if application is a script file or frozen exe
if getattr(sys, 'frozen', False):
application_path = os.path.dirname(sys.executable)
elif __file__:
application_path = os.path.dirname(__file__)
config_path = os.path.join(application_path, config_name)
Determining application path in a Python EXE generated by pyInstaller
I found a solution. You need to check if the application is running as a script or as a frozen exe:
import os
import sys
config_name = 'myapp.cfg'
# determine if application is a script file or frozen exe
if getattr(sys, 'frozen', False):
application_path = os.path.dirname(sys.executable)
elif __file__:
application_path = os.path.dirname(__file__)
config_path = os.path.join(application_path, config_name)
auto-py-to-exe/pyinstaller base_library error
Just found the solution so I'm posting it for anyone looking for it:seems like the current directory becomes \current directory\base_library.zip so sys.path[0] will return that instead of the directory the executable resides(something similar for the standalone --onefile .exe,same solution).The solution is simply to replace sys.path[0] with sys.path[0]).replace('\base_library.zip',''),which will allow the script to acces the current directory again.
Related Topics
Rotate Axis Text in Python Matplotlib
How to Check If a String Contains an Element from a List in Python
Pandas: Filter Rows of Dataframe with Operator Chaining
Sort() and Reverse() Functions Do Not Work
How to Get Text with Selenium Webdriver in Python
Printing All Instances of a Class
Why Is Python 3.X's Super() Magic
How to Run Multiple While Loops at a Time in Pygame
Why Does (1 in [1,0] == True) Evaluate to False
How to Filter Query Objects by Date Range in Django
Return a Default Value If a Dictionary Key Is Not Available
How to Convert SQLalchemy Row Object to a Python Dict
Scrape Multiple Urls Using Qwebpage