I am getting this error "No /Root object! - Is this really a PDF?" using my MAC computer with Python 2.7 and PDFMiner version 20110515.
The pdf files are not damaged because the same program with the same files works on my PC computer! Also I have tried many pdfs and this error exists for all of them. Any ideas of what I should change in my MAC to not to get this error?
I found the source of the problem:
I had a method to read all the files in a directory and parse them. Turns out that I had one hidden file in that directory that was not a pdf file!
Here is how I fixed the problem:
for filename in os.listdir(INPUT_DIR_NAME):
if filename.endswith('.pdf'):
#do stuff!
Related
So I've read through countless people asking similar questions but none seemed to be the answer I was needing.
Tonight I started the W3 Python tutorial. I downloaded the latest version of Python.
The first task is to go into a text editor, in this case I chose Notepad. I copied the following:
print("Hello World!")
and saved that as helloworld.py
I made sure it was in my C: drive... which is the only one I have anyway.
I used cmd.exe and typed in C:\Users\MyName>python helloworld.py
And I get the error: python: can't open file 'C:\Users\18327\helloworld.py': [Errno 2] No such file or directory
It is saving into my documents folder, is that the issue?
Your file's directory is 'C:\Users\18327\Documents\helloworld.py', while your directory specified in cmd is 'C:\Users\18327\helloworld.py'. Instead, run cmd in the Documents folder.
I am practicing some API work in python 3.7 using API star 0.5.X and my python script can't find the .json file that is in the same folder as the python file. I am working on and running the script with Atom editor and I am working in a venv, which is fairly new to me.
I am using a helper function to load in the JSON data using a "with open()" statement. I have tried using the relative and absolute file paths, and in both instances it is unable to locate the file. I have tried launching the file in Atom using terminal and the MacOS finder.
This is what I have so far:
import json
from typing import List
import os
from apistar import App, Route, types, validators
from apistar.http import JSONResponse
print(os.getcwd())
os.chdir('/Users/{myusernamehere}/100days/apistar')
print(os.getcwd())
#helpers
def _load_employee_data():
with open('employees.json') as f:
employees = json.loads(f.read())
return employees
the second print statement prints the correct file path, being the one that 'employees.json' and 'app.py' are located in.
Since the problem is specific to your setup, it's hard to reproduce or provide a solution in code. Your code itself looks to be fine, but there are two things that are likely to be the cause of your issues:
When your script is running, Python needs access to the appropriate source folders and installed packages; you should let something like virtualenv manage this through a virtual environment. From the terminal, you can load the appropriate virtual environment with:/path/to/your/venv/Scripts/activate.sh
If you do, you should expect your script to find the same libraries it did during development in that virtual environment. Make sure you include something like a requirements.txt in your project to allow easy reinstalling of the same modules on a different machine, in a new virtual environment.
Your script, when run by Python, has a 'working directory'. This is the directory that Python is started from and your script not being able to find the file (even though it may be in the same folder as the script itself) is probably due to Python being started from a different directory.
This was a problem due to how the Atom editor works. It was solved by switching to vim.
I only partially understand but apparently this had something to do with Atom having a separate temp directory for working files, or something of that nature. When using vim to edit the script, and then calling it in the terminal the problem was resolved.
Okay, So i had the same issue with i.c.w. VScode :
file = open('file.txt')
print(file.name)
resulted in
FileNotFoundError
file.txt was 100% in the same folder... According to finder on my Mac, ánd the folder column in VS code!
i was pulling out my hair. Switched a lot of interpreters, local python and Conda, to Python 3.8 instead of 3.9, back to python 2.8.
Nothing mattered.
Till I changed :
file = open('file.txt') to: file = open('file.txt', 'a')
It didn't suddenly work, but I saw immediately in the "folder column" of VScode a new file.txt file popping up. In an entirely different folder then where the pythonfile.py was located. So after that; I pushed all local repo's to their remotes; deleted the whole caboodle, and installed them one by one in a new folder through git clone. I opened a new workspace added those project folders and since then it works like a charm.
What exactly went wrong ; im sorry, I have no idea. But for me, a fresh install of the repo's and VScode workspace is what did the trick.
I recently had the same error, on Visual Studio Code, I managed to solve it by instead of clicking the Run Python button, I used the terminal to cd into the project directory and run the python script like that, and no problems!
I am trying to os.chdir() into system32 from python on windows, but when i attempt to change into this directory I am getting this error:
FileNotFoundError: [WinError 2] The system cannot find the file specified:
'/System32/
So obviously Python can't see this directory but I don't know why because os.listdir() shows this directory in the list. Does this have to do with the permissions that python has? Ultimately my goal is to change into the winevt directory to pull and dump the log files and to check for any errors, so any way to grab these is completely fine. My intuition was simply to change into the directory, open and read the log files and then check for errors, then print and report those errors.
Your current working directory may be different from the one where folder is.
Use this to check your current working directory before changing the directory.
print('Present DIR is : ',os.getcwd())
Then go to the correct directory and change the directory.
When you try to get into System32, use absolute path rather than the relative path, with the following:
os.chdir(r'C:/Windows/System32')
or in your case:
os.chdir(r'C:\Windows\System32\winevt\Logs')
As Archit said, you might not be in the correct directory.
The solution to this problem was a little bit hard to come by. I first tried uninstalling python 32 bit but that just broke everything.
I eventually installed python36 and added the python36.dll and the location of this dll to the user and system path (on Windows). Then I made sure to remove anything in the path involving python 34 or python36-32 which is the 32 bit version of python. This then allowed my to easily os.chdir into system32
I’m a fairly new python user and I’m having an issue with the open() function where python isn’t able to find the files that I’m trying to work with. I’m using Python 3.5, PyCharm CE and macOS Sierra. I have a feeling the issue is caused by the fact that I’m using a mac and macs come preinstalled with python 2.7, which has caused me issues with things like adjusting filepaths and installing packages in the past.
Here’s what I’ve tried so far:
Referencing just the file name:
file = open("file_name.txt", "r").read()
Referencing the file from within the folder its in (on my desktop)
file = open(“folder_name/file_name.txt", "r").read()
Referencing the entire file path:
file = open("/Users/username\ 1/Desktop/folder_name/file_name.txt", "r").read()
Creating a new directory within the project and manually
adding files I’m trying to reference to the new directory:
print (os.getcwd())
>>> Users/username/PycharmProjects/Project_Name
os.mkdir(“directory_name”)
file = open("/Users/username/PycharmProjects/Project_Name/directory_name/file_name.txt", "r").read()
adding both the file while both in the folder sitting on my desktop and sitting alone on my desktop to the filepath
sys.path.append("/Users/User_Name\ 1/Desktop/Folder_name/File_name.txt")
sys.path.append("/Users/User_Name\ 1/Desktop/file_name.txt")
I’m getting basically this error message or some variation of it:
FileNotFoundError: [Errno 2] No such file or directory: ‘file_name.txt'
Thank you very much!!
>>> print (os.getcwd())
Users/username/PycharmProjects/Project_Name
So that's your current working directory. If you want to open a file that's on the desktop, you're going to have to tell Python that's where it is.
You can indicate your home directory ("/Users/username" on OS X or "/home/username" on Linux systems) with "~". Prove it in Python with:
>>> os.path.expanduser('~')
"/Users/username"
>>> os.path.expanduser('~/Desktop')
"/Users/username/Desktop"
So to open a file that's on your desktop, you can point Python to it with:
open(os.path.expanduser('~/Desktop/filename.txt'))
the error is :
Errors occurred
See the logfile 'D:\Program Files\Google\google_appengine\launcher\GoogleAppEngineLauncher.exe.log' for details
Why?
Find your home directory (open command prompt, run "set home" to see what it is). Go to that directory and delete the directory called "Google"
more here: http://code.google.com/p/googleappengine/issues/detail?id=2299
Solution:
Note: The wrong directories are stated above.
Go to C:\Users\your username\Google directory.
Delete google_appengine_launcher.ini and google_appengine_projects.ini
Appengine should now start successfully, absent error message.
yeah just like RyanW mentioned the link, Delete the .ini files viz. google_appengine_launcher.ini & google_appengine_projects.ini in the user Directory in folder named Google.
Had this error as well.
No log file.
C:/Users//Google/ was empty and no ini file there.
Ivan's solution didn't help.
I'm running a 64bit Win8 machine and this is what I had to do:
Remove my 64 bit python 2.7 install
Install 32 bit python 2.7 (direct link)
launch googleappengine installer and choose "Repair".
Voila.
Not enough points to provide a comment on the answers above hence the stand alone answer. If you delete the ini files as per the other answers the pathways to your projects in the launcher will likely also be gone. In my case however I simply moved the ini files out of the C:\Users\your username\Google directory and then after opening and closing the launcher successfully once I reinstated the ini files into the Google directory again, after which the launcher worked and the project pathways were retained.