pyinstaller, file not found traceback error - python

I modified the .spec file with the following
`a.datas += [
('WORDS', '\words.txt', 'DATA'),
('CITIES', '\cities.txt', 'DATA'),
('ANIMALS', '/canimals.txt', 'DATA'),
]`
after a = Analysis(...). When i go to run pyinstaller on the spec file i get the following traceback error
`Cannot find ('ANIMALS', '/canimals.txt', 1, 'x')
Traceback (most recent call last):
File "c:\python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python37\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
File "c:\python37\lib\site-packages\PyInstaller\__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "c:\python37\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\python37\lib\site-packages\PyInstaller\building\build_main.py", line 844, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\python37\lib\site-packages\PyInstaller\building\build_main.py", line 791, in build
exec(code, spec_namespace)
File "hangman.spec", line 37, in <module>
console=True )
File "c:\python37\lib\site-packages\PyInstaller\building\api.py", line 424, in __init__
strip_binaries=self.strip, upx_binaries=self.upx,
File "c:\python37\lib\site-packages\PyInstaller\building\api.py", line 196, in __init__
self.__postinit__()
File "c:\python37\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
self.assemble()
File "c:\python37\lib\site-packages\PyInstaller\building\api.py", line 281, in assemble
pylib_name=pylib_name)
File "c:\python37\lib\site-packages\PyInstaller\archive\writers.py", line 334, in __init__
super(CArchiveWriter, self).__init__(archive_path, logical_toc)
File "c:\python37\lib\site-packages\PyInstaller\archive\writers.py", line 61, in __init__
self._add_from_table_of_contents(logical_toc)
File "c:\python37\lib\site-packages\PyInstaller\archive\writers.py", line 86, in _add_from_table_of_contents
self.add(toc_entry) # The guts of the archive.
File "c:\python37\lib\site-packages\PyInstaller\archive\writers.py", line 381, in add
fh = open(pathnm, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: '/canimals.txt'`
when its running for the other files in the a.datas it doesnt produce any errors, ive verified the existence of the 'canimals.txt' file and its there, and ive deleted and recreated the file and its still giving me the same error, i dont understand whats going on since the file clearly exists. im new with pyinstaller and i was following suggestions from my previous question and now ive seem to reach an impasse. What do i do?
edit: this is the code that queries the program to open the specified files
if decision == '1':
b = WordBank('words.txt')
bank = b.returnBank()
elif decision == '2':
b = WordBank('cities.txt')
bank = b.returnBank()
elif decision == '3':
b = WordBank('canimals.txt')
bank = b.returnBank()
the WordBank class is as follows
class WordBank:
def __init__(self, file):
file = open(file, 'r')
self.word_bank = file.readlines()
self.word_bank = ''.join(self.word_bank)
self.word_bank = self.word_bank.split('\n')
i get the error
Traceback (most recent call last):
file "hangman.py", line 212. in <module>
file "wordbank.py", line 3, in __init__
FileNotFoundError: [Errno 2] No such file or directory 'cities.txt'
[11452] failed to execute script hangman
do i have to specify the file path using the os module?

Your problem is evident from the error message:
FileNotFoundError: [Errno 2] No such file or directory: '/canimals.txt'`
You say that the file "canimals.txt" exists. But your code is not looking for a file named "canimals.txt". It's looking for a file named "/canimals.txt". That forward slash is your problem. I'm guessing that you're on Windows, where a forward slash is just an arbitrary character in a filename or directory name.
The problem is further made clear by the fact that you say the other two files work, and you have backslashes in front of their names rather than a forward slash. Turn the forward slash into a backslash, and I bet your code will work as you desire.
Also, you should be able to remove the backslashes from in front of the file names and have your code still work. A single backslash used that way is attempting to "escape" the character that follows it. But escaping regular letters just gives you the letter itself, so in this case, the backslashes aren't doing anything.

Related

Python buildozer, ValueError

Good afternoon! I'm asking for help, I can't figure out python buildozer for a day, I've already prepared everything, and at the final stage, when the "buildozer android debug" command is entered into the terminal, it gives such an error at the end. Can anyone tell me what to do about it and how to fix it?
Here is the error itself:
Traceback (most recent call last):
File "/usr/local/bin/buildozer", line 11, in <module>
load_entry_point('buildozer==0.40.dev0', 'console_scripts', 'buildozer')()
File "/usr/local/lib/python3.6/dist-packages/buildozer-0.40.dev0-py3.6.egg/buildozer/scripts/client.py", line 13, in main
Buildozer().run_command(sys.argv[1:])
File "/usr/local/lib/python3.6/dist-packages/buildozer-0.40.dev0-py3.6.egg/buildozer/__init__.py", line 1071, in run_command
self.target.run_commands(args)
File "/usr/local/lib/python3.6/dist-packages/buildozer-0.40.dev0-py3.6.egg/buildozer/target.py", line 92, in run_commands
func(args)
File "/usr/local/lib/python3.6/dist-packages/buildozer-0.40.dev0-py3.6.egg/buildozer/target.py", line 102, in cmd_debug
self.buildozer.prepare_for_build()
File "/usr/local/lib/python3.6/dist-packages/buildozer-0.40.dev0-py3.6.egg/buildozer/__init__.py", line 178, in prepare_for_build
self.target.install_platform()
File "/usr/local/lib/python3.6/dist-packages/buildozer-0.40.dev0-py3.6.egg/buildozer/targets/android.py", line 666, in install_platform
self._install_android_ndk()
File "/usr/local/lib/python3.6/dist-packages/buildozer-0.40.dev0-py3.6.egg/buildozer/targets/android.py", line 459, in _install_android_ndk
cwd=self.buildozer.global_platform_dir)
File "/usr/local/lib/python3.6/dist-packages/buildozer-0.40.dev0-py3.6.egg/buildozer/__init__.py", line 699, in download
urlretrieve(url, filename, report_hook)
File "/usr/lib/python3.6/urllib/request.py", line 1826, in retrieve
block = fp.read(bs)
File "/usr/lib/python3.6/tempfile.py", line 624, in func_wrapper
return func(*args, **kwargs)
ValueError: read of closed file
I tried to find an answer to this question, but so far without success.

WinError 32, Python, file used by another process

I have a script that is searching through files in a folder for multiple functions, one of which is verifying if they are valid. If they are corrupt, it moves them to another location. When trying to move the file, I get an error that it is being used by another process. I've looked through other similar questions, but none seem to resolve my issue.
path = filedialog.askdirectory()
pathbad = filedialog.askdirectory()
conv = os.path.basename(os.path.normpath(path))
bad = os.path.basename(os.path.normpath(pathbad))
jpg_list = []
badfiles = []
nojpg = []
cbz_list = [str(pp) for pp in path.glob("**/*.cbz")]
cbr_list = [str(pp) for pp in path.glob("**/*.cbr")]
file_list = cbr_list + cbz_list
for file in file_list:
if ('.cbr' in file) or ('.rar' in file):
try:
with rarfile.RarFile(file) as MyRar:
rarcontents = MyRar.namelist()
rarcontents = [x.lower() for x in rarcontents]
if any('.jpg' in s for s in rarcontents):
jpg_list.append(file)
else:
nojpg.append(file)
except (rarfile.BadRarFile):
badfiles.append(file)
except:
continue
if len(badfiles) > 0:
print('Moving ', len(badfiles), ' bad archives to "Bad Files":\n')
for zfile in badfiles:
nfile = zfile.replace(conv, bad)
shutil.move(zfile, nfile)
It errors on the shutil.move command. The file is actually copied to the new location, but not deleted from the old. I have verified that the file is not open in any application outside of python, and the only place it's open in python uses a with statement, which (as I understand it) closes the file when complete.
Edit:
Complete Stack Trace
File "C:\Program Files\Python39\lib\shutil.py", line 806, in move
os.rename(src, real_dst)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'Q:\\Download\\Comics\\Various Files\\Convert\\Poptropica 01.cbr' -> 'Q:\\Download\\Comics\\Various Files\\Bad Files\\Poptropica 01.cbr'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\Users\azure\.vscode\extensions\ms-python.python-2021.8.1105858891\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\azure\.vscode\extensions\ms-python.python-2021.8.1105858891\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\Users\azure\.vscode\extensions\ms-python.python-2021.8.1105858891\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "C:\Program Files\Python39\lib\runpy.py", line 268, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Program Files\Python39\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "i:\dev\comix\cbz_JPG-to-WEBP.py", line 138, in <module>
shutil.move(zfile, nfile)
File "C:\Program Files\Python39\lib\shutil.py", line 827, in move
os.unlink(src)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'Q:\\Download\\Comics\\Various Files\\Convert\\Poptropica 01.cbr'
If you are on windows open the task manager and close the python prosseses
Restart PC

Decompiling PYC file with Uncompyle6 getting AssertionError

I am trying to recover the original python scripts from a pyinstaller exe. I was able to extract the files from the exe and obtain the magic number. From what I read, the main .py file (found in the extract folder with no suffix) just needs to be renamed to main.pyc and the magic number appended should work. I followed these instructions and it worked, but my issue is the other .pyc files (found in the PYZ-00.pyz_extracted) all error out when I try to decompile them with uncompyle6 - even when I append the magic number. The error I'm getting is:
Unknown type 0
Traceback (most recent call last):
File "c:\users\hahenry\anaconda3\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\hahenry\anaconda3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\hahenry\Anaconda3\Scripts\uncompyle6.exe_main_.py", line 7, in
File "c:\users\hahenry\anaconda3\lib\site-packages\uncompyle6\bin\uncompile.py", line 193, in main_bin
result = main(src_base, out_base, pyc_paths, source_paths, outfile,
File "c:\users\hahenry\anaconda3\lib\site-packages\uncompyle6\main.py", line 316, in main
deparsed = decompile_file(
File "c:\users\hahenry\anaconda3\lib\site-packages\uncompyle6\main.py", line 208, in decompile_file
decompile(
File "c:\users\hahenry\anaconda3\lib\site-packages\uncompyle6\main.py", line 83, in decompile
assert iscode(co)
AssertionError

Pandas Dedupe not working . Multiprocessing and Permission error

I was trying to clean up duplicates in an excel file using dedupe.
The code worked fine at first and the code itself is simple. But whenever I run the code I get the below error. The code works fine if I delete all the temp files, restart pycharm or restart my computer and it won't run for the second time.
The data file is a csv file with a list of random similar name in column A with header as 'Name'. Please help tp resolve. Thank you.
Code
import pandas as pd
import pandas_dedupe
#loading data
df = pd.read_csv('duplicate.csv')
#deduplication process
df_final = pandas_dedupe.dedupe_dataframe(df,['Name'])
#save to csv
df_final.to_csv('cleansed_output.csv')
Getting error below
C:\Users\Username\AppData\Roaming\Python\Python38\site-packages\pandas_dedupe\utility_functions.py:17: FutureWarning: The default value of regex will change from True to False in a future version.
df[i] = df[i].str.replace('[^\w\s\.\-\(\)\,\:\/\\\\]','')
Reading from dedupe_dataframe_learned_settings
Clustering...
Traceback (most recent call last):
File "C:\Users\Username\AppData\Roaming\Python\Python38\site-packages\dedupe\api.py", line 103, in score
matches = core.scoreDuplicates(pairs,
File "C:\Users\Username\AppData\Roaming\Python\Python38\site-packages\dedupe\core.py", line 244, in scoreDuplicates
process.start()
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\multiprocessing\spawn.py", line 125, in _main
prepare(preparation_data)
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\multiprocessing\spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 265, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\Username\PycharmProjects\Duplicate\main.py", line 10, in <module>
df_final = pandas_dedupe.dedupe_dataframe(df,['Name'])
File "C:\Users\Username\AppData\Roaming\Python\Python38\site-packages\pandas_dedupe\dedupe_dataframe.py", line 249, in dedupe_dataframe
clustered_df = _cluster(deduper, data_d, threshold, canonicalize)
File "C:\Users\Username\AppData\Roaming\Python\Python38\site-packages\pandas_dedupe\dedupe_dataframe.py", line 143, in _cluster
clustered_dupes = deduper.partition(data, threshold)
File "C:\Users\Username\AppData\Roaming\Python\Python38\site-packages\dedupe\api.py", line 170, in partition
pair_scores = self.score(pairs)
File "C:\Users\Username\AppData\Roaming\Python\Python38\site-packages\dedupe\api.py", line 108, in score
raise RuntimeError('''
RuntimeError:
You need to either turn off multiprocessing or protect
the calls to the Dedupe methods with a
`if __name__ == '__main__'` in your main module, see
https://docs.python.org/3/library/multiprocessing.html#the-spawn-and-forkserver-start-methods
Traceback (most recent call last):
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 616, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\USERNAME~1.KAB\\AppData\\Local\\Temp\\tmpp9123_pc\\blocks.db'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 802, in onerror
_os.unlink(path)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\USERNAME~1.KAB\\AppData\\Local\\Temp\\tmpp9123_pc\\blocks.db'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\weakref.py", line 642, in _exitfunc
f()
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\weakref.py", line 566, in __call__
return info.func(*info.args, **(info.kwargs or {}))
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 817, in _cleanup
cls._rmtree(name)
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 813, in _rmtree
_shutil.rmtree(name, onerror=onerror)
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 740, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 618, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 805, in onerror
cls._rmtree(path)
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\tempfile.py", line 813, in _rmtree
_shutil.rmtree(name, onerror=onerror)
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 740, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 599, in _rmtree_unsafe
onerror(os.scandir, path, sys.exc_info())
File "C:\Users\Username\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 596, in _rmtree_unsafe
with os.scandir(path) as scandir_it:
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\\Users\\USERNAME~1.KAB\\AppData\\Local\\Temp\\tmpp9123_pc\\blocks.db'
Process finished with exit code -1
The answer is in the error:
You need to either turn off multiprocessing or protect the calls to the Dedupe methods with a if __name__ == '__main__' in your main module
Change your code to the following, and try again:
import pandas as pd
import pandas_dedupe
if __name__ == "__main__":
#loading data
df = pd.read_csv('duplicate.csv')
#deduplication process
df_final = pandas_dedupe.dedupe_dataframe(df,['Name'])
#save to csv
df_final.to_csv('cleansed_output.csv')

Robot Frame work: Error While running .robot file in python interpreter using robot.run (windows environment)

I am trying to execute Run_Keyword.robot made with RIDE file which is in directory 'Robot' from python interpreter and getting following error. I am able to run this .py file from cmd without any error and it gives expected results. What can be the reason for this. I am a newbie to Robot Framework. Please help with this.
from robot import run
run('C:\\Users\\uvijayac\\Desktop\\Robot')
The Error I am getting is as follows.
Traceback (most recent call last):
File "C:\Users\uvijayac\Desktop\Robot\rf.py", line 27, in <module>
run_tests()
File "C:\Users\uvijayac\Desktop\Robot\rf.py", line 23, in run_tests
report=report_file)
File "C:\Python27\lib\site-packages\robot\run.py", line 471, in run
return RobotFramework().execute(*datasources, **options)
File "C:\Python27\lib\site-packages\robot\utils\application.py", line 83, in execute
return self._execute(list(arguments), options)
File "C:\Python27\lib\site-packages\robot\utils\application.py", line 89, in _execute
return self._report_error(unicode(err), help=True)
File "C:\Python27\lib\site-packages\robot\utils\application.py", line 110, in _report_error
self._logger.error(message)
File "C:\Python27\lib\site-packages\robot\output\loggerhelper.py", line 59, in error
self.write(msg, 'ERROR')
File "C:\Python27\lib\site-packages\robot\output\loggerhelper.py", line 62, in write
self.message(Message(message, level, html))
File "C:\Python27\lib\site-packages\robot\output\logger.py", line 109, in message
logger.message(msg)
File "C:\Python27\lib\site-packages\robot\output\monitor.py", line 66, in message
self._writer.error(msg.message, msg.level, clear=self._running_test)
File "C:\Python27\lib\site-packages\robot\output\monitor.py", line 142, in error
self._highlight('[ ', level, ' ] ' + message, error=True)
File "C:\Python27\lib\site-packages\robot\output\monitor.py", line 158, in _highlight
self._write(before, newline=False, error=error)
File "C:\Python27\lib\site-packages\robot\output\monitor.py", line 154, in _write
stream.flush()
IOError: [Errno 9] Bad file descriptor
>>>

Categories

Resources