Pyinstaller "ValueError: Can't mix absolute and relative paths" - python-3.x

I am using windows 10 and anaconda3 to manage my python packages. This is my first time to use python, and I'm trying to make my own gui program with pyqt5. Also I'm trying to make .exe file using Pyinstaller. The issue I am running into is that the .exe is throwing the error block:
(pyqt5_env) C:\Python Projects>pyinstaller -w -F App_ver05.py
268 INFO: PyInstaller: 4.0.dev0+b3dd91c8a8
268 INFO: Python: 3.7.7 (conda)
268 INFO: Platform: Windows-10-10.0.18362-SP0
Traceback (most recent call last):
File "c:\anaconda3\envs\pyqt5_env\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\anaconda3\envs\pyqt5_env\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Anaconda3\envs\pyqt5_env\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "c:\anaconda3\envs\pyqt5_env\lib\site-packages\PyInstaller\__main__.py", line 112, in run
spec_file = run_makespec(**vars(args))
File "c:\anaconda3\envs\pyqt5_env\lib\site-packages\PyInstaller\__main__.py", line 58, in run_makespec
spec_file = PyInstaller.building.makespec.main(filenames, **opts)
File "c:\anaconda3\envs\pyqt5_env\lib\site-packages\PyInstaller\building\makespec.py", line 458, in main
specfile.write(onefiletmplt % d)
File "c:\anaconda3\envs\pyqt5_env\lib\site-packages\PyInstaller\building\makespec.py", line 101, in __repr__
self.variable_prefix, self.filename_suffix = make_variable_path(self.path)
File "c:\anaconda3\envs\pyqt5_env\lib\site-packages\PyInstaller\building\makespec.py", line 84, in make_variable_path
if os.path.commonpath([filename, from_path]) == from_path:
File "c:\anaconda3\envs\pyqt5_env\lib\ntpath.py", line 615, in commonpath
raise ValueError("Can't mix absolute and relative paths") from None
ValueError: Can't mix absolute and relative paths
The same error occurs regardless of which .py file is used. For information, I wrote the used code below.
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
class MyApp(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
btn1 = QPushButton('&Button1', self)
btn1.setCheckable(True)
btn1.toggle()
vbox = QVBoxLayout()
vbox.addWidget(btn1)
self.setLayout(vbox)
self.setWindowTitle('QPushButton')
self.setGeometry(300, 300, 300, 200)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())
I uninstalled and reinstalled pyinstaller but it didn't work. I don't think its a code issue because the code is really simple. Can anyone give a solution or hint for this problem?

What happened for me is that the absolute path name had a space in it. Once the project was moved to a directory without spaces it was able to build

The solution of this problem is to use the full file name and append the flag -F to the file name. In your case for example if for the file App_ver05.py the absolute path is :
/home/user123/Desktop/foldername/App_ver05.py
Then use the command :
pyinstaller -F /home/user123/Desktop/foldername/App_ver05.py

Related

Kivy in Jypiter notebook: OSError: source code not available

Im̀ trying to create a code that uses kivy library to create a window that has a button as widget. To do that I used the following code copied from a online video so as far as I know it should work:
(Each running cell will be divided by some dots, as the first one runs with no problems but the second is where the error occures)
from kivy.app import App
from kivy.uix.button import Button
from kivy.interactive import InteractiveLauncher
from kivy.lang import Builder
#forzar a la app a no iniciar en pantalla completa
from kivy.config import Config
Config.set("graphics", "fullscreen", "0")
janela = None
glayout= None
...
class WindowApp(App):
pass
window = WindowApp()
wi = InteractiveLauncher(janela)
wi.run()
#the error that appears on the console after running the second cell goes like this:
[WARNING] [Deprecated ] Call to deprecated function __init__ in /home/alfred/anaconda3/envs/k39/lib/python3.10/site-packages/kivy/interactive.py line 308.Called from /tmp/ipykernel_5673/4179568724.py line 5 by <module>().
Exception in thread Thread-5 (startApp):
Traceback (most recent call last):
File "/home/alfred/anaconda3/envs/k39/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
self.run()
File "/home/alfred/anaconda3/envs/k39/lib/python3.10/threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "/home/alfred/anaconda3/envs/k39/lib/python3.10/site-packages/kivy/interactive.py", line 319, in startApp
app.run(*args, **kwargs)
File "/home/alfred/anaconda3/envs/k39/lib/python3.10/site-packages/kivy/app.py", line 954, in run
self._run_prepare()
File "/home/alfred/anaconda3/envs/k39/lib/python3.10/site-packages/kivy/app.py", line 923, in _run_prepare
self.load_kv(filename=self.kv_file)
File "/home/alfred/anaconda3/envs/k39/lib/python3.10/site-packages/kivy/app.py", line 676, in load_kv
default_kv_directory = dirname(getfile(self.__class__))
File "/home/alfred/anaconda3/envs/k39/lib/python3.10/inspect.py", line 785, in getfile
raise OSError('source code not available')
OSError: source code not available
kvcode= """
FloatLayout:
Button:
size_hint: .1, .1
pos_hint: {"x":.3, "top": 1.}
text: "A"
"""
glayout= Builder.load_string(kvcode)
janela.root_window.add_widget(glayout)
After running the last cell a black window that crashes appears. So far Im quite new to using the Kivy library so Im̀ quite lost about what counld have gonne wrong since I've seen this code run without problems online.

Kivy MDDataTable IndexError: list index out of range when dynamically add and remove rows

I am using Kivy MDDataTables in a Python3 App. During runtime i want to dynamically add and remove rows in the table. When I add data using add_row(self, data: Union[list, tuple]), afterwards remove the rows using remove_row(self, data: Union[list, tuple]) and then start to fill the table again, it crashes after 20 to 50 rows with the following error message:
[INFO ] [Base ] Leaving application in progress...
Traceback (most recent call last):
File "<PATH TO PROGRAM>\test.py", line 93, in <module>
sm.run()
File "<PATH TO VIRTUAL ENV>\lib\site-packages\kivy\app.py", line 950, in run
runTouchApp()
File "<PATH TO VIRTUAL ENV>\lib\site-packages\kivy\base.py", line 582, in runTouchApp
EventLoop.mainloop()
File "<PATH TO VIRTUAL ENV>\lib\site-packages\kivy\base.py", line 347, in mainloop
self.idle()
File "<PATH TO VIRTUAL ENV>\lib\site-packages\kivy\base.py", line 387, in idle
Clock.tick()
File "<PATH TO VIRTUAL ENV>\lib\site-packages\kivy\clock.py", line 733, in tick
self.post_idle(ts, self.idle())
File "<PATH TO VIRTUAL ENV>\lib\site-packages\kivy\clock.py", line 776, in post_idle
self._process_events()
File "kivy\_clock.pyx", line 616, in kivy._clock.CyClockBase._process_events
File "kivy\_clock.pyx", line 649, in kivy._clock.CyClockBase._process_events
File "kivy\_clock.pyx", line 645, in kivy._clock.CyClockBase._process_events
File "kivy\_clock.pyx", line 218, in kivy._clock.ClockEvent.tick
File "<PATH TO VIRTUAL ENV>\lib\site-packages\kivy\uix\recycleview\__init__.py", line 257, in refresh_views
lm.set_visible_views(indices, data, viewport)
File "<PATH TO VIRTUAL ENV>\lib\site-packages\kivy\uix\recyclelayout.py", line 253, in set_visible_views
refresh_view_layout(index, opt, widget, viewport)
File "<PATH TO VIRTUAL ENV>\lib\site-packages\kivy\uix\recycleview\layout.py", line 148, in refresh_view_layout
self.apply_selection(index, view, index in self.selected_nodes)
File "<PATH TO VIRTUAL ENV>\lib\site-packages\kivy\uix\recycleview\layout.py", line 143, in apply_selection
view.apply_selection(self.recycleview, index, is_selected)
File "<PATH TO VIRTUAL ENV>\lib\site-packages\kivymd\uix\datatables\datatables.py", line 1804, in apply_selection
ic = instance_table_data.recycle_data[index].get("icon", None)
IndexError: list index out of range
I tried this on Windows 10 and Raspbian 11 using:
Python 3.9
Kivy v2.0.0
KivyMD 1.0.0.dev0, git-Unknown, 2022-03-21, directly installed from Github
Virtual Environment via Anaconda resp. venv
Packages installed via Anaconda resp. pip
In an older version of the Program, I used kivymd 0.104.2 and directly added and removed the data to self._table.row_data. In this version of the program the same crash happens.
I see that there is an Index out of range Error, but i have no impact to change that.
What can i do to fix the program and avoid the crash?
Example Code:
from kivymd.app import MDApp
from kivy.uix.screenmanager import ScreenManager
from kivy.uix.screenmanager import Screen
from kivymd.uix.datatables import MDDataTable
from kivy.metrics import dp
import threading
import time
class TestScreen(Screen):
def __init__(self, **kw):
super().__init__(**kw)
self._table = None
self.createTable()
def createTable(self):
self._table = MDDataTable(
rows_num=99,
column_data=[("col1", dp(10)),
("col2", dp(50)),
("col3", dp(20)),
("col4", dp(30)),
("col5", dp(15)),
("col6", dp(15)),
("col7", dp(15)),
])
self.add_widget(self._table)
def clearTable(self):
while len(self._table.row_data) > 0:
self._table.remove_row(self._table.row_data[-1])
def updateTable(self, data):
for item in data:
row = (str(len(self._table.row_data)),
item[0],
item[1],
item[2],
item[3],
item[4],
item[5])
self._table.add_row(row)
def addData(self):
self.updateTable([("1", "1", "1", "1", "1", "1", "1")] * 5)
def getTableSize(self):
return len(self._table.row_data)
class TestApp(MDApp):
def build(self):
sm = ScreenManager()
sm.add_widget(TestScreen())
return sm
class DataProvider(threading.Thread):
def __init__(self, sm):
threading.Thread.__init__(self)
self.sm = sm
def run(self):
time.sleep(1)
sm.root.current_screen.addData()
time.sleep(1)
sm.root.current_screen.clearTable()
while True:
sm.root.current_screen.addData()
time.sleep(1)
print(sm.root.current_screen.getTableSize())
sm = TestApp()
data_p = DataProvider(sm)
data_p.start()
sm.run()
I added the bug to the bug tracker of kivymd github project. You can follow its progress there!

FFMPEG - [WinError 2] The system cannot find the file specified

I'm having an issue using the FFmpeg package.
Here's my code :
import ffmpeg_streaming
from ffmpeg_streaming import Formats, Bitrate, Representation, Size
_360p = Representation(Size(640, 360), Bitrate(276 * 1024, 128 * 1024))
_480p = Representation(Size(854, 480), Bitrate(750 * 1024, 192 * 1024))
_720p = Representation(Size(1280, 720), Bitrate(2048 * 1024, 320 * 1024))
hls = video.hls(Formats.h264())
hls.representations(_360p, _480p, _720p)
hls.output('C:/Users/juled/Videos/testStreaming')
Quite simple as you can see, found it on the web.
And here's the error message I have:
Traceback (most recent call last):
File "C:\Users\juled\OneDrive\Bureau\PACT\streamingMultimedia\streaming.py", line 50, in <module>
hls.output('C:/Users/juled/Videos/testStreaming')
File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\site-packages\ffmpeg_streaming\_media.py", line 93, in output
self.run(ffmpeg_bin, monitor, **options)
File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\site-packages\ffmpeg_streaming\_media.py", line 121, in run
asyncio.run(self.async_run(ffmpeg_bin, monitor, **options))
File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\asyncio\runners.py", line 43, in run
return loop.run_until_complete(main)
File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\asyncio\base_events.py", line 583, in run_until_complete
return future.result()
File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\site-packages\ffmpeg_streaming\_media.py", line 112, in async_run
self._run(ffmpeg_bin, monitor, **options)
File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\site-packages\ffmpeg_streaming\_media.py", line 105, in _run
with Process(self, command_builder(ffmpeg_bin, self), monitor, **options) as process:
File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\site-packages\ffmpeg_streaming\_process.py", line 58, in __init__
self.process = _p_open(commands, **options)
File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\site-packages\ffmpeg_streaming\_process.py", line 29, in _p_open
return subprocess.Popen(shlex.split(commands), **options)
File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "C:\Users\juled\OneDrive\Bureau\Informatique\WPy64-3760\python-3.7.6.amd64\lib\subprocess.py", line 1207, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
I've been checking every file quoted in the error message, but only one of them is "my" code, the others are FFmpeg and Python libraries codes.
I'm using IDLEX for Python 3.7.6 on Windows by the way.
I've tried to change some of the FFmpeg library code, especially where subprocess.Popen appears, by putting a shell=True in the parameters. New Error Message, different this time.
I've added FFmpeg to the PATH, no change.
I've reinstalled FFmpeg to be sure, but no change. I'm using this version: python-ffmpeg-video-streaming-0.1.14.
Do any of you have a solution I could try ?
Oh and a friend has the same issue on MAC.
This is a PATH environment variable issue. Based on this link, you could try:
import os
path = 'the path you want'
os.environ['PATH'] += ';'+path
to add the path to ffmpeg.exe to your system path (and also to check if your python instance is really looking at the correct path), and you can also change pythonpath,
import sys
sys.path.insert(0,'path/to/ffmpeg')
Note how these two are totally different. However, I find that the easiest way with programs like ffmpeg, which are self-contained executables, that you can just copy them to the working directory of your script and then run it, which is what solved your problem.

Unable to run python file

I have been trying to run a python script, but I keep on getting the following error.
Error:
Traceback (most recent call last):
File "cloud_copasi/background_daemon/cloud_copasi_daemon.py", line 18, in <module>
django.setup()
File "/Users/cloudcopasi/cloud-copasi/venv/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/cloudcopasi/cloud-copasi/venv/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/Users/cloudcopasi/cloud-copasi/venv/lib/python3.8/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'web_interface'
The script file which I am trying to run (cloud_copasi_daemon) is:
import sys, time
import django
django.setup()
from tools.daemon import Daemon
import tools.background_script
from tools.response import RemoteLoggingResponse
from cloud_copasi import settings
import logging
log=logging.getLogger(__name__)
class MyDaemon(Daemon):
#Set the level we wish to log at. Logs are sent back to the central server
#Choices are all, debug, info, error, none
def __init__(self, *args, **kwargs):
return super(MyDaemon, self).__init__(*args, **kwargs)
def stop(self, *args, **kwargs):
return super(MyDaemon, self).stop(*args, **kwargs)
def run(self):
log.debug('Daemon running')
while True:
min_repeat_time = settings.DAEMON_POLL_TYME #Seconds
start_time = time.time()
try:
tools.background_script.run()
log.debug('Background script finished')
except Exception as e:
log.exception(e)
finish_time = time.time()
difference = finish_time - start_time
if difference < min_repeat_time:
time.sleep(min_repeat_time - difference)
if __name__ == "__main__":
daemon = MyDaemon('/tmp/Cloud-COPASI.pid')
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
daemon.start()
elif 'stop' == sys.argv[1]:
daemon.stop()
elif 'restart' == sys.argv[1]:
daemon.restart()
else:
print ("Unknown command")
sys.exit(2)
sys.exit(0)
else:
print("usage: %s start|stop|restart" % sys.argv[0])
sys.exit(2)
"web_interface" is the Django App and I have verified that the path referring to it is correct. I don't know where else do I need to fix the file path to get this python script to work.
I am having the same problem on Mac OS Big Sur (running Python 3.8) as well as on Linux CentOS (running Python 3.6).
Any help is much appreciated.
When you are trying to bootstrap django like this you need to make sure to set the environment variable PYTHONPATH to include the folder where web_interface lives. I'm guessing that your cloud_copasi_daemon.py is in a different folder than web_interface so when you run python cloud_copasi_daemon.py it looks in the immediate folder in which you invoked the script and can't find it.

How can solve error in autopytoexe to compile python program to exe?

when I try to compile program in python 3.7
with:
auto-py-to-exe v2.6.0
Selenium
The code is:
from selenium import webdriver
import pathlib
import resource
fn = pathlib.Path(__file__).parent / 'chromedriver.exe'
browser = webdriver.Chrome(fn)
browser.get('website')
# fill in username and hit the next button
username = browser.find_element_by_id('user_login')
username.send_keys('xxxxxxx')
password = browser.find_element_by_id('user_pass')
password.send_keys('xxxxxxxxxx')
nextButton1 = browser.find_element_by_id('wp-submit')
nextButton1.click()
browser.get('website')
nextButton2 = browser.find_element_by_class_name('add-new-h2')
nextButton2.click()
nextButton3 = browser.find_element_by_id('is_continue_no')
nextButton3.click()
nextButton4 = browser.find_element_by_class_name('rad10')
nextButton4.click()
error in compile
An error occurred, traceback follows:
Traceback (most recent call last):
File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\auto_py_to_exe-2.6.0-py3.7.egg\auto_py_to_exe\__main__.py", line 259, in convert
pyi.run() # Execute PyInstaller
File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\building\build_main.py", line 838, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\building\build_main.py", line 784, in build
exec(text, spec_namespace)
File "<string>", line 29, in <module>
File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\building\api.py", line 424, in __init__
strip_binaries=self.strip, upx_binaries=self.upx,
File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\building\api.py", line 196, in __init__
self.__postinit__()
File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
self.assemble()
File "e:\documentos\proyectos\synctango2woocomerce\venv\lib\site-packages\PyInstaller\building\api.py", line 273, in assemble
pylib_name = os.path.basename(bindepend.get_python_library_path())
File "C:\Users\Jesus-NewPC\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 214, in basename
return split(p)[1]
File "C:\Users\Jesus-NewPC\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 183, in split
p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType
all log
i expect correct compile
i try
install windows sdk
install visual c++ libraries
need help to resolve the problem
this is the code from my python program
One problem with your code is that you are trying to load chromedriver.exe which can be found in your current directory but after freezing it cannot be loaded anymore. When you want to freeze your app with Pyinstaller you first need to add that file to your output executable and then load it from the temp directory.
I'm not sure about auto-py-to-exe but you can use the below code and then use
pyinstaller -F --add-data "chromedriver.exe;." yourscript.py
from selenium import webdriver
import resource
import sys
import os
def resource_path(relative_path):
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath("."), relative_path)
fn = resource_path('chromedriver.exe')
browser = webdriver.Chrome(fn)
browser.get('website')
# fill in username and hit the next button
username = browser.find_element_by_id('user_login')
username.send_keys('xxxxxxx')
password = browser.find_element_by_id('user_pass')
password.send_keys('xxxxxxxxxx')
nextButton1 = browser.find_element_by_id('wp-submit')
nextButton1.click()
browser.get('website')
nextButton2 = browser.find_element_by_class_name('add-new-h2')
nextButton2.click()
nextButton3 = browser.find_element_by_id('is_continue_no')
nextButton3.click()
nextButton4 = browser.find_element_by_class_name('rad10')
nextButton4.click()
Solved in the simplest way, pass the proyect folder with the script to
  disk C: and the errors were solved gave error while it was saved in disk E:

Resources