I have the following code:
import os
print (os.listdir("C:/Windows/System32/config"))
print (os.listdir("C:/Windows/System32/winevt"))
I am running this Python script as an administrator and confirmed those directories in fact exist.
The first line outputs with some files and folders, but not all files. For example, there is a registry hive contained within called "SOFTWARE" which does not appear in the output.
The second line says the path wasn't identified. Here is the full output:
['Journal', 'RegBack', 'systemprofile', 'TxR']
Traceback (most recent call last):
File "test.py", line 3, in <module>
print (os.listdir("C:/Windows/System32/winevt"))
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:/Windows/System32/winevt'
This module (os.listdir), works pretty much everywhere else on the system, but not within System32. I suspect this may be permission related, but am not too sure on how to fix it as I am already running the script as an administrator.
Help would be appreciated. Thanks!
Related
I have just finished a project where I have made a connect 4 game and am trying to convert it to an exe file using auto-py-to-exe.
I want to use the one-file option, however every time it finishes and I run it, it would come up with an error:
Failed to execute script 'main' due to unhandled exception: No file 'Assets/icon.png' found in working directory '...'
Then in the box it says:
Traceback (most recent call last):
File "main.py", line 32, in <module>
FileNotFoundError: No file 'Assets/window-icon.png' found in working directory '...'.
I've tried quite a few alterations, e.g. not using the image, but then it would come up with the same error but for a different added file.
How can I fix this?
EDIT: I've tried it again by using the os module and giving the full directories to all the files in main.py, but that hasn't changed anything.
I was also facing this problem then I got the solutions from analysing other threads.
You have to update your script by adding this function
import sys
import os
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path=getattr(sys,'_MEIPASS',os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
and changing address of every additional files used in your script
for example
icon = resource_path("game.icon")
You just have to use auto-py-to-exe just like shown below
Showing the options you can just use
Add all the files used in the Additional File section of it and make sure that the period(.) is there in the destination
That's it !
I have a csv file and I put it at D:\Subin\PYTHON\AppleStore.csv
Then I launch my Jupyter Notebook with the url: http://localhost:8888/notebooks/PYTHON/test.ipynb
I try to run this script:
open_file = open('AppleStore.csv')
Then I get the issue:
FileNotFoundError Traceback (most recent call last)
<ipython-input-25-7784a3a20685> in <module>
----> 1 open_file = open('AppleStore.csv')
FileNotFoundError: [Errno 2] No such file or directory: 'AppleStore.csv'
the test.ipynb is at same directory with AppleStore.csv But I dont understand why I got file not found issue.
Anyone have idea about this?
If you are running python from within Jupyter, your working directly is likely where Juptyer is installed. Within your notebook, use print("my path is ", os.getcwd()) to check what your working directory is. (credit to gelonida)
Either use the full path to the file, or change your current working directory to the folder where the file is. os.chdir(FOLDER PATH GOES HERE)
For both of the code samples in this answer, you'll need to first import os.
I am quite new to Python and I am having problems opening a file in Python.
I want to open a text file called 'coolStuff' in a Folder on my Desktop and this is how I type in the command but I still get an error message. The file exists and so I do not understand why I get that error message.
open("coolStuff.txt","r")
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
open("coolStuff.txt","r")
FileNotFoundError: [Errno 2] No such file or directory: 'coolStuff.txt'
If you want to simply supply a filename like coolStuff.txt without also providing a full directory, then you have to make sure that Python is running in the same directory as the file. If you aren't sure what directory Python is running in, try this:
import os
print(os.getcwd())
You have two options:
let's say your file is in C:\path\to\dir\coolStuff.txt
1.
open(r'C:\path\to\dir\coolStuff.txt','r')
2.
import os
os.chdir(r'c:\path\to\dir')
open('coolStuff.txt', 'r')
Because the file you want to open is not in the current directory.You can find the file 'coolStuff.txt' in the terminal and launch your python environment at the same directory.
I'm trying to run a script in python3.4 & windows 8 .
It worked well with windows 7 but now, in windows 8.1 it can´t write a file in C: , may be access denied.
If I change the directory, for example User/xxx it works, but I don´t know how to do to 'write' in C:
with open('C:/xxxx.csv', 'r') as csvfile:
Traceback (most recent call last):
File "C:\Python34\Scripts_jmab\csv_to_shp.py", line 12, in <module>
urllib.request.urlretrieve(a,filename)
File "C:\Python34\lib\urllib\request.py", line 188, in urlretrieve
tfp = open(filename, 'wb')
OSError: [Errno 22] Invalid argument: 'C:/xxxxx.csv'
thanks
Due to security settings in Windows, users are not allowed to create files in the root C:\ folder, as some important system files reside there that could be attacked by viruses. While it is possible to disable this feature, the easiest (and safest) solution is to create a directory for your programs to put their output files in. C:\TEMP is a good location (you can create it if it doesn't already exist), or you can make another folder named according to your own choosing.
This is the error i get:
Traceback (most recent call last):
File "dwload.py", line 9, in <module>
File "Pmw\__init__.pyc", line 28, in <module>
WindowsError: [Error 3] The system cannot find the path specified: "C:\\Users\\P
'sao\\Desktop\\dist\\library.zip\\Pmw/*.*"
I get the error after compiling the python file into the executable with py2exe.
Does anybody know why i get this error?
Found the solution: http://billyjin.kodingen.com/punbb-1.3.4/viewtopic.php?id=310
Well, the error message says that the path was not found, and if you look at the path, you appear to have mixed up backslashes and slashes as path separators. How are you constructing the path you're using?
I had the same problem when using pyinstaller and tkinter table (py 2.7). The problem was solved by removing the Pwm dependency in the tkintertable lib metadata. Its will help you, if pwm dont used in program
Finally, I found the solution:
First, you need to run the bundlepmw.py in the C:\Python27\Lib\site-packages\Pmw\build\lib\Pmw\Pmw_1_3\bin folder following this command: python bundlepmw.py C:\Python27\Lib\site-packages\Pmw\Pmw_1_3\lib to create the Pmw.py.
Read this page: folk.uio.no/hpl/scripting/doc/python/Pmw/dynamicloader.html, after fixing the bundlepmw.py based on this link sourceforge.net/p/pmw/discussion/33675/thread/f0bd7f34.
You should be able to generate the Pmw.py file.
Then copy the Pmw.py plus PmwBlt.py and PmwColor.py into the main script directory and run your setup.py. Sweet