I recently updated PyMuPDF/fitz and so updated my code that uses it to update my use of fitz methods to match the updated naming convention (see PyMuPDF > Deprecated Names).
Problem: when I call a function I wrote to use fitz's Page.get_text() it sometimes exists as an attribute under the deprecated name and sometimes is in the updated name. Either way it is called, it is imported in the same script, but in one version second script imports the script that imports fitz (via from fitz import fitz).
How can I gain visibility into where these different sets are attributes are introduced?
Steps taken so far to disentangle and debug: I confirmed the version of PyMuPDF is the same in both situations via this StackOverflow answer with:
print(pkg_resources.get_distribution('PyMuPDF').version) => 1.21.0
I checked the attributes of the object with:
print(dir(page))
It is a consistent pattern based on which script I use to call my function.
#1 w/ getText (deprecated):
screenshot showing version number 1.21.0 and getText as an attribute
#2 w/ get_text:
screenshot showing version number 1.21.0 and get_text as an attribute
Current solution:
for page in doc:
try:
text += page.get_text()
except AttributeError:
text += page.getText()
There are a few ways to handle situations aroung name deprecation:
You can enable old names by executing fitz.restore_aliases() right after import. This will make old names available again (but keep the new ones too).
You can execute a utitlity we have provided. This can be given folders as parameters (or single Python files). It will walk through the source code and replace old names with new ones. You also can request backups of your Python files. Folders will be processed recursively.
I'm currently looking to make an updater program for my plugins for guildwars 2, but I got a little issue for the last download. The name of the file to download isn't consistent from version to version as you can see there. Asking the creator to update it so it is consistent is already something that has been done some month ago, but as the updates are fairly rare and nothing has been done.
Would there be a way to get either all the release files, or to downlaod the using filter so it doesn't get the other ones?
For now i've been using the following code to download the other plugins and write them to the corresponding file, but this method doesn't work at all with that specific one because the name of this release changes.
(using python 3.9.6)
import requests
test = requests.get('https://github.com/knoxfighter/arcdps-killproof.me-plugin/releases/latest/download/d3d9_arcdps_killproof_me.dll', allow_redirects=True)
print("code :" + str(test.status_code))
open('d3d9_arcdps_killproof_me.dll', 'wb').write(test.content)
Any ideas on how I could work arround this and still download this last plugin?
If you're looking for an example of how to call git pull from within python, this seems to be a good solution:
The code is using this library:
https://github.com/gitpython-developers/GitPython
import git
g = git.cmd.Git(git_dir)
g.pull()
I'm very new to python and this is also my first post here, so please don't be angry if I make some mistakes. I'm trying my best to explain my problem :)
I wanted to track the ISS with 2 servos, so I downloaded the SatTrack library (more information about it here: https://devpost.com/software/sattrack) with Python 2.7.9. I installed all the other required librarys and installed the setup.py file.
When I was done I typed in the command > python -m sattrack.interactive into the cmd as the instruction said and the visualsation of the current position of the ISS worked completly fine.
Then I tiped in the code:
from sattrack import SatTrack # Import the `SatTrack` class:
s = SatTrack() # Instantiate class
s.set_location(lat='0', lon='0', ele=100) # Set observer location
s.get_tle('ISS') # Search CELESTRAK or AMSAT for satellite TLE data
s.begin_computing() # Start calculating topocentric coordinates
s.show_location() # Start printing satellite data to console
s.visualize() # Start a server and visualize satellite on map in browser
into the IDLE and pressed on "Run Module", but I just received the error message from above. This programme does the same thing as the small command above (At least I think so), but it's needed for the servo control code.
So, how do I fix this? :)
The page you found on "devpost.com" seems to be out of date. Generally, the GitHub repository will be the most up-to-date source of documentation on a project. The devpost.com page links to the repository, which is here:
https://devpost.com/software/sattrack
The current README shows no show_location() call, presumably because it has been removed and is no longer supported? It was removed in the most recent update to the repository, in March 2017:
https://github.com/hazrmard/SatTrack/commit/6eef1c921c7a64b4a777b9148aa076640627facf
Alas, there is no explanation of why the change is made, or why that method is no longer supported.
I may sound rather uninformed writing this, and unfortunately, my current issue may require a very articulate answer to fix. Therefore, I will try to be specific as possible as to ensure that my problem can be concisely understood.
My apologizes for that- as this Python code was merely obtained from a friend of mine who wrote it for me in order to complete a certain task. I myself had had extremely minimal programming knowledge.
Essentially, I am running Python 3.6 on a Mac. I am trying to work out a code that allows Python to scan through a bulk of a particular website's potentially existent subdomains in order to find possibly-existent JPG images files contained within said subdomains, and download any and all of the resulting found files to a distinct folder on my Desktop.
The Setup-
The code itself, named "download.py" on my computer, is written as follows:
import urllib.request
start = int(input("Start range:100000"))
stop = int(input("End range:199999"))
for i in range(start, stop + 1):
filename = str(i).rjust(6, '0') + ".jpg"
url = "http://website.com/Image_" + filename
urllib.request.urlretrieve(url, filename)
print(url)
(Note that the words "website" and "Image" have been substituted for the actual text included in my code).
Before I proceed, perhaps some explanation would be necessary.
Basically, the website in question contains several subdomains that include .JPG images, however, the majority of the exact URLs that allow the user to access these sub-domains are unknown and are a hidden component of the internal website itself. The format is "website.com/Image_xxxxxx.jpg", wherein x indicates a particular digit, and there are 6 total numerical digits by which only when combined to make a valid code pertain to each of the existent images on the site.
So as you can see, I have calibrated the code so that Python will initially search through number values in the aforementioned URL format from 100000 to 199999, and upon discovering any .JPG images attributed to any of the thousands of link combinations, will directly download all existent uncovered images to a specific folder that resides within my Desktop. The aim would be to start from that specific portion of number values, and upon running the code and fetching any images (or not), continually renumbering the code to work my way through all of the possible 6-digit combos until the operation is ultimately a success.
(Possible Side-Issue- Although I am fairly confident that my friend's code is written in a manner so that Python will only download .JPG files to my computer from images that actually do exist on that particular URL, rather than swarming my folder with blank/bare files from every single one of URL attempts regardless of whether that URL happens to be successful or not, I am admittedly not completely certain. If the latter is the case, informing me of a more suitable edit to my code would be tremendously appreciated.)
The Execution-
Right off the bat, the code experienced a large error. I'll list through the series of steps that led to the creation of said error.
#1- Of course, I first copy-pasted the code into a text document, and saved it as "download.py". I saved it inside of a folder named "Images" where I sought the images to be directly downloaded to. I used BBEdit.
#2- I proceeded, in Terminal, to input the commands "cd Desktop/Images" (to account for the file being held within the "Images" folder on my Desktop), followed by the command "Python download.py" (to actually run the code).
As you can see, the error which I obtained following my attempt to run the code was the ImportError: No module named request. Despite me guessing that the answer to solving this is simple, I can legitimately say I have got such minimal knowledge regarding Python that I've absolutely no idea how to solve this.
Hint: Prior to making the download.py file, the folder, and typing the Terminal code the only interactions I made with Python were downloading the program (3.6) and placing it in my toolbar. I'm not even quite sure if I am required to create any additional scripts/text files, or make any additional downloads before a script like this would work and successfully download the resulting images into my "Images" folder as is my desired goal. If I sincerely missed something integral at any point during this long read, hopefully, someone in here can provide a thoroughly detailed explanation as to how to solve my issue.
Finishing statements for those who've managed to stick along this far:
Thank you. I know this is one hell of a read, and I'm getting more tired as I go along. What I hope to get out of this question is
1.) Obviously, what would constitute a direct solution to the "No module named request" Input Error in Terminal. In other words, what I did wrong there or am missing.
2.) Any other helpful information that you know would assist this code, for example, if there is any integral step or condition I've missed or failed to meet that would ultimately cause the entirety of my code to cease to work. If you do see a fault in this, I only ask of you to be specific, as I've not got much experience in the programming world. After all, I know there is a lot of developers out here that are far more informed and experienced than am I. Thanks.
urllib.request is in Python 3 only. When running 'python' on a Mac, you're running Python 2 by default. Try running executing with python3.
python --version
might need to
brew install python3
urllib.request is a Python 3 construct. Most systems run Python 2 as default and this is what you get when you run simply python.
To install Python 3, go to https://brew.sh/ and follow the instructions to install the Hombrew package manager. Then run
brew install python3
python3 download.py
I am having some issues with my code for doing the final implementation for a data to image library using the JPEG DCT2/3 process. Linked below is the source code that I am using. I am using the python code under the SageMathCloud. I've been trying to figure out this specific error for the past several hours, and no matter how I do it, it just doesn't work. I get the same error message everytime, and I just can't track down the reason why.
Gist