Код: Выделить всё
def resource_path(self, relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
Код: Выделить всё
def save_data_nomor(self):
# Get input from QLineEdit
new_number = self.ui.inputNomor.text().strip()
# Check if input is empty
if new_number == "":
print("Number cannot be empty.")
return
# Load data from JSON file (if available)
file_path = self.resource_path('database\\data_nomor.json')
try:
if os.path.exists(file_path):
with open(file_path, 'r') as file:
data_nomor = json.load(file)
else:
data_nomor = {"nomor": []} # If the file doesn't exist, create empty data
except Exception as e:
print(f"Error reading JSON file: {e}")
data_nomor = {"nomor": []}
# Add new location to data (avoid duplicates)
if new_number not in data_nomor["nomor"]:
data_nomor["nomor"].append(new_number)
# Save data to JSON file
try:
with open(file_path, 'w') as file:
json.dump(data_nomor, file, indent=4)
print(f"Number '{new_number}' successfully saved.")
except Exception as e:
print(f"Error saving JSON file: {e}")
# Clear input after saving
self.ui.inputNomor.clear()
Код: Выделить всё
pyinstaller --name SmartTank --onefile --windowed --icon=icon.ico --add-data "database;database" --add-data "images;images" --add-data "font;font" main.py Тогда я использовал другой способ, а именно конвертацию в .exe, а не в один файл, с помощью этой команды:
Код: Выделить всё
pyinstaller --name SmartTank --windowed --icon=icon.ico --add-data "database;database" --add-data "images;images" --add-data "font;font" main.py Теперь проблема возникает здесь: когда я конвертирую его в настройку с помощью компилятора Inno Setup, первоначальная проблема появляется снова. Когда я создаю установленное приложение, оно не может сохранять данные. Так в чем же решение?
Я несколько раз пытался конвертировать в .exe разными способами, но все равно не получилось.
Подробнее здесь: https://stackoverflow.com/questions/791 ... -qt-to-exe
Мобильная версия