Shelve Module Not Working - python

After I reinstalled Python to move it from an AppData folder to Program Files, it looks like the shelve module is no longer working and I receive the error below when I call upon shelve.open().
Please help!
>>> import shelve
>>> myShelf = shelve.open('data')
Traceback (most recent call last):
File "C:\Program Files\Python\lib\dbm\dumb.py", line 81, in _create
f = _io.open(self._datfile, 'r', encoding="Latin-1")
FileNotFoundError: [Errno 2] No such file or directory: 'data.dat'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
myShelf = shelve.open('data')
File "C:\Program Files\Python\lib\shelve.py", line 243, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "C:\Program Files\Python\lib\shelve.py", line 227, in __init__
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
File "C:\Program Files\Python\lib\dbm\__init__.py", line 94, in open
return mod.open(file, flag, mode)
File "C:\Program Files\Python\lib\dbm\dumb.py", line 303, in open
return _Database(file, mode, flag=flag)
File "C:\Program Files\Python\lib\dbm\dumb.py", line 69, in __init__
self._create(flag)
File "C:\Program Files\Python\lib\dbm\dumb.py", line 83, in _create
with _io.open(self._datfile, 'w', encoding="Latin-1") as f:
PermissionError: [Errno 13] Permission denied: 'data.dat'
>>>

The error "FileNotFoundError: [Errno 2] No such file or directory: 'data.dat'" shows you, it can not find the data.dat, please check the file location.

I had this problem using Windows 10. I solved the issue by changing the working directory to a folder under my profile.
os.chdir('C:\\Users\\Nat\\Documents\\Python\\Project 1')
I presume I didn't have permission to write a file 'Program Files'.

Related

Compile Cython Extensions Error - Pycharm IDE. Linux Mint

Non-zero exit code (1):
Traceback (most recent call last):
File "/snap/pycharm-community/315/plugins/python-ce/helpers/pydev/setup_cython.py", line 242, in main()
File "/snap/pycharm-community/315/plugins/python-ce/helpers/pydev/setup_cython.py", line 233, in main with FrameEvalModuleBuildContext():
File "/snap/pycharm-community/315/plugins/python-ce/helpers/pydev/setup_cython.py", line 187, in __enter__ shutil.copy(compatible_c, self._c_file)
File "/usr/lib/python3.9/shutil.py", line 427, in copy copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/usr/lib/python3.9/shutil.py", line 266, in copyfile with
open(dst, 'wb') as fdst: OSError: [Errno 30] Read-only file system: '/snap/pycharm-community/315/plugins/python-ce/helpers/pydev/_pydevd_frame_eval/pydevd_frame_evaluator.c'
I did as written here, but it doesn't work yet.
Please tell me what else can be done.

Why does Virtual Studio code keep failing to fine file or directory in python

I run my code in Pythons build in IDLE Shell and it will run no problem. But once it is in virtual studio it then throws this error code.
I have gone into my Python Extension settings and have checked the 'Execute In File Dir' like multiple other posts and fixes say, but it does not seem to resolve my issue.
Error:
Traceback (most recent call last):
File "c:\Users\dpr48\OneDrive\Desktop\Python\FINAL PROJECT\Versions\v1.0.0\Cipher Text -
v1.0.0\CipherText-v1.0.0.py", line 27, in <module>
mainwindow = MainMenu()
File "c:\Users\dpr48\OneDrive\Desktop\Python\FINAL PROJECT\Versions\v1.0.0\Cipher Text -
v1.0.0\CipherText-v1.0.0.py", line 17, in __init__
loadUi('MainMenu.ui', 'r', self)
File "C:\Users\dpr48\AppData\Local\Programs\Python\Python39\lib\site-
packages\PyQt5\uic\__init__.py", line 238, in loadUi
return DynamicUILoader(package).loadUi(uifile, baseinstance, resource_suffix)
File "C:\Users\dpr48\AppData\Local\Programs\Python\Python39\lib\site-
packages\PyQt5\uic\Loader\loader.py", line 66, in loadUi
File "C:\Users\dpr48\AppData\Local\Programs\Python\Python39\lib\site-
packages\PyQt5\uic\uiparser.py", line 1020, in parse
document = parse(filename)
File "C:\Users\dpr48\AppData\Local\Programs\Python\Python39\lib\xml\etree\ElementTree.py",
line 1229, in parse
tree.parse(source, parser)
File "C:\Users\dpr48\AppData\Local\Programs\Python\Python39\lib\xml\etree\ElementTree.py",
line 569, in parse
source = open(source, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'MainMenu.ui'

Failed to execute script 'App-Name.py' due to unhandled exception: [Errno 2] No such file or directory

I made a python app using pygame and pygame-gui library. I've been getting this error when I try to run the python app that I've converted into an exe file. I used this command: pyinstaller App-Name.py --hidden-import=data.jsonfile --onefile --noconsole for creating the executable. And when I try to run it, it gives me this error:
Failed to execute script 'App-Name.py' due to unhandled exception: [Errno 2] No such file or directory: 'C:\Users\Acer\AppData\Local\Temp\_MEI164642\data\jsonfile\theme-1.json'
Traceback (most recent call last):
File "App-Name.py", line 508, in <module>
File "App-Name.py", line 37, in __init__
File "pygame_gui\ui_manager.py", line 68, in __init__
File "pygame_gui\core\ui_appearance_theme.py", line 624, in load_theme
File "importlib\resources.py", line 103, in read_text
File "importlib\resources.py", line 82, in open_text
File "importlib\resources.py", line 46, in open_binary
File "PyInstaller\loader\pyimod03_importers.py", line 542, in open_resource
File "pathlib.py", line 1117, in open
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Acer\\AppData\\Local\\Temp\\_MEI164642\\data\\jsonfile\\theme-1.json'
I've tried looking for the answer anywhere but nothing works so far. Any help would be appreciated!
try reinstalling pyinstaller or try other modules such as cx_freeze

Sublime Text doesn't compile with Anaconda

I've just installed Sublime Text, trying to test out this IDE, I'm trying to put this simple line of code in:
from matplotlib import pyplot as plt
x = range(100)
y = [x**2 for x in x]
plt.plot(x, y)
Just to test it out, and I'm getting an error message:
Traceback (most recent call last):
File "./python3.3/subprocess.py", line 1104, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 1050, in run_
return self.run(**args)
File "C:\Users\Or Work\AppData\Roaming\Sublime Text 3\Installed Packages\Conda.sublime-package\commands.py", line 526, in run
File "C:\Users\Or Work\AppData\Roaming\Sublime Text 3\Installed Packages\Conda.sublime-package\commands.py", line 489, in __enter__
File "C:\Users\Or Work\AppData\Roaming\Sublime Text 3\Installed Packages\Conda.sublime-package\commands.py", line 473, in conda_version
File "./python3.3/subprocess.py", line 576, in check_output
File "./python3.3/subprocess.py", line 819, in __init__
File "./python3.3/subprocess.py", line 1110, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified
Does anybody knows how to fix this?
P.s I am using Anaconda as my python environment
Thanks for helping!

cannot run webdriver.Firefox from selenium webdriver

I am having trouble using Selenium
I am using Python 3.6, on a Windows 7 machine at my workplace. Firefox is 61.0.1 (64-bit)
Python is loaded in C:\Program Files (x86)\Python36-32
My work is in H:\PythonPrograms
I have successfully installed selenium:
C:\Windows\System32>pip install selenium
Requirement already satisfied: selenium in c:\program files (x86)\python36-32\lib\site-packages (3.13.0)
Per other advice found here, I downloaded geckodriver.exe and placed it both into C:\Program Files (x86)\Python36-32 and H:\PythonPrograms.
My path includes: C:\Program Files (x86)\Python36-32\Scripts\;C:\Program Files (x86)\Python36-32\;H:\PythonPrograms
I am following the steps on "Automate the Boring Stuff with Python" (Al Sweigart) p. 257
>>> from selenium import webdriver
>>> browser = webdriver.Firefox()
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
browser = webdriver.Firefox()
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 159, in __init__
log_path=log_path)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\service.py", line 44, in __init__
log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None
PermissionError: [Errno 13] Permission denied: 'geckodriver.log'
>>> browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 159, in __init__
log_path=log_path)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\service.py", line 44, in __init__
log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None
PermissionError: [Errno 13] Permission denied: 'geckodriver.log'
>>>
(IT's not the permissaion on geckodriver.log. This even happens when I delete that file and try again. Also I checked permissions: )
When I run Python as administrator from a new Python session:
>>> from selenium import webdriver
>>> browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 160, in __init__
self.service.start()
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'PythonPrograms' executable needs to be in PATH.
I don't understand what is happening between me running Python normally vs running as administrator. Whichever, neither way gives me expected output.
added new run example by changing the executable_path to include the program name and remove the "r" qualifier. Here are the new results:
>>> from selenium import webdriver
>>> browser = webdriver.Firefox(executable_path='H:\PythonPrograms\geckodriver.exe')
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
browser = webdriver.Firefox(executable_path='H:\PythonPrograms\geckodriver.exe')
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 170, in __init__
keep_alive=True)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 251, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
>>>
Instead of using regular expression try to give exact path with exe file name
browser = webdriver.Firefox(executable_path='H:\PythonPrograms\yourexenamehere.exe')

Categories

Resources