For the past day I have been trying to incorporate pdf2image into my flask webservice.
The problem is, whatever I do, I still get the "Is poppler installed and in PATH?" error message.
I have written a little program that just prints the number of pages in a pdf file. This works completely fine, inside and outside the venv containing flask. If I try to do this from the flask file, I get the error. I even tried calling the very same function in the test code, but to no avail. I don't really know what to do anymore, so any help is greatly appreciated.
P.S.: I don't really know what source to include for this post, so just feel free to ask and I will provide it.
I had the symptoms which you describe. For me the problem was the following:
in the .service file used by systemd to start gunicorn, I had an incomplete path variable. The solution was to add the path to pdftoppm and pdftocairo, which in my case (on Debian 10) was /usr/bin
The solution is therefore that the .service file includes
[Service]
...
Environment="PATH=<your_app_path>/venv/bin:/usr/bin"
Note: This problem and its solution are thus broader than a pdf2image issue, but it seems to show up frequently with pdf2image... assuming this is true, I hope that your question and my response are both relevant.
Related
I have a question regarding simple imports that I cannot get my head around.
Take a look at the attached screenshot to see my project layout.
The file somefile.py imports the class SayHello from a file called someclass.py and calls it. someotherfile.py does the exact same thing. They both use from someclass import SayHello.
In Pycharm both files run. However, From the command line or from VSCode somefile.py runs, but someotherfile.py errors out with the following error:
ModuleNotFound: No module named 'someclass'.
I believe it has something to do with PYTHONPATH/environment variables or something like that, but every explanation I have read has confused me thus far (Even this one which I thought was going to set me strait Relative imports for the billionth time).
Can someone explain in simple terms what is happening here? What is Pycharm doing by default that other editors are not such that my imported modules are found? How can I make someotherfile.py work in VSCode without modifying it?
Thanks in advance!
Pycharm adds your project directory into python paths by default. See configuration of "Pycharm run" that you execute and you shall see few checkboxes like
If those checked Pycharm creates PYTHONPATH environment variable for you that instructs Python where to look for someclass module.
You will have to configure VSCode to define PYTHONPATH environemnt variable for python command you run and include your root project directory path on it.
TLDR: Mess with the line starting with ./automated pointing it to various directories in your project until it works haha.
Long rambling answer: Alright now that I am not in a frenzy from trying to figure this out and it has been a day, I feel like I can make a conherint response (lets see if that is true).
So my original answer was an attempt to simplify my problem into what I thought was the issue due to a ModuleNotFound error I was getting. I had been trying to get unittests in Python inside of Visual Studio code to work (hint hint just use Pycharm it just works out of the box in there), but the integrated testing feature or whatever could not find my tests giving ModuleNotFound as the reason.
The solution to my problem actually just concerned the line ./automated-software-testsing-with-python/blog.
In the below screenshot the relevant part is ./automated-software-testing-with-python/blog.
This is it when it is correctly configured (My tests work Woo hoo!)
Now you can go ahead and read the official documentation for what this line is doing, but I am convinced that the documentation is wrong. Due to how my code is structured and how my files are named, what the documentation says its looking for definitely does not exist. But that is another can of worms...
I actually got it to work by accident. Originally when you go though the wizard to set up what's in that screenshot above, it defaulted to ./automated-software-testing-with-python which did not work. I then manually edited it to something else that was not the below screenshot hoping to get it to work.
It was only when I pointed it to that blog directory on accident (thinking I was in a different file due to trying to debug this for hours and hours in a blind rage) that it ended up working.
I did a bunch of PYTHONPATH manipulation and Environment Variable mumbo jumbo, and I originally thought that that had an effect, but when I cloned my repot to my other machine (which did not have any of that Environment Variable PYTHONPATH stuff going on) it worked too (again, provided that the line in question pointed to blog.
Ok hopefully that might help somone someday, so I'll end it there. Not to end on a bitter sounding zinger, but I will never cease be amazed by how doing such simple things such as configuring the most basic unit test can be so difficult in our profession haha. Well now I can start working. Thanks for the help to those who answered!
I have a script that generates logs based on an equation. Initially I had no equation so it printed out “0”. I run the script through my IDE, the equation works. I compiled with PyInstaller, run it, it’s all the same, except the log is back to printing “0”.
Any idea what the cause could be?
I just spent quite some time struggling with the same problem, but found a solution. I know it's a bit late, but I'm leaving this for people who may find this useful in the future.
I have just found out that I had two versions of the folder containing my script: one of them was the one I was actively working with, and the other one was an outdated version whose existence I didn't even remember. Turns out PyInstaller was importing the outdated version instead of the one I was working with.
I figured this out by looking at the .toc files inside the build folder. I searched the 'Analysis-00.toc' file for my script, and found out that it was importing the wrong one. I deleted the wrong outdated script, cleaned all the pyinstaller files and created a new build. After that, it worked as it should.
I've installed a package called 'prince' to use MCA (multiple correspondance analysis).
I had an issue while executing the code and I've noticed that someone else posted that issue on github and there was a merge pull request to solve that issue.
Since the installation doesn't take that into account, I tried to copy the new script inplace of the previous one and run the code but now I get this error 'attempted relative import beyond top-level package' from the first import which wasn't the case before even if the import was there too.
So I guess when you modify the script even a little bit there's something particular that happen's ? Maybe it's a minor thing and I could still get away with it but I don't quite understand the mechanics here, could someone help me please ?
Thanks !
(P.S : I'm using Python 3.6 on Anaconda)
EDIT : Aaron solved, in this specific case, the problem I had. That being said I'd still be interested to know how I it could be done if one notices something in the source code and wants to modify it.
I am trying to use a .py file that I wrote called "sentence" as an import to index.py.
They are both in the app's main/home folder. To import, I am saying
import sentence
And the app works fine when I test in Komodo. But when I push to heroku, my application becomes an error page. The logging addon I have shows that the error is
ImportError: No module named sentence
I have tried numerous solutions suggested on many different places, and none have worked. I have tried adding __init__.py to the folder. I have tried reinstalling flask to my application and my computer. I have tried moving files to and from /static thinking maybe my files are static resources, but to no avail.
What else can I do to troubleshoot this problem?
I figured out the problem. At least for my situation. I forgot that linux and windows treat capitalization in filenames differently. Upon refactoring some elements of the app, I renamed 'Sentence' to 'sentence.' I discovered this by pulling a fresh repo on a different machine. To fix it, I moved the offending file out of the local repo folder, committed and pushed, then added it back in, committed and pushed. Went back to working as soon as I did that.
If you're having the same issue and this didn't solve it, I'm sorry! Get in touch with me and maybe by the time you're reading this I'll have more experience and can help you better than I helped myself.
At work we are using Trac on several internal wiki's and an external wiki. REcently we found the need for a new plugin. After we going through a few tutorials we went to install a plugin to make sure it would work. It didn't. We've been going through trying to figure out. Below I will list the steps and various things I did while trying to get it to work.
1) I went to trac-hacks website and downloaded their hellow world plugin, figured I couldn't make a mistake using their code.
2) I compiled and made an egg using python setup.py bdist_egg on the machine where trac is installed, to make sure it's the same Python version being used.
3) I then copied it over to /directory/where/trac/is/plugins/ folder and chmod 755 the file egg file.
4) I then restarted http, unable to find a better way of restaring trac so this may be where my problem is. It didn't work. So I deleted the egg folder in plugins
5) Uploaded it via trac->administration->plugins and restarted httpd again. Nothing.
6) I realized I had to edit the trac.ini file and added helloworld.* = enabled under component and restarted the web server.
It's quite possible it's me but any help would be greatly appreciated!
Its the helloworld plugin from trachack, essentially displays hello world and theres a button. There are no error messages provided, hence why googling was hard.
I'm assuming that it's using root and that's the user I built it with. I will look into seeing if it's anybody else, just taking a quick look though I don't see anything else that could be using it. I only copied the egg file to the plugins folder, I set up another folder elsewhere and built it and cp to the plugins folder. I'm glad to know I was doing that right because looking up documentation on how to restart trac turns up practically nothing, they just say restart trac or restart apache. I will look into the logs later on tomorrow. Thanks for the replies! Also we are using trac .12.1.
So after looking at the log files it seems that it doesn't even load the plugin, can't find anywhere that says it's loading or any errors with it. Now we have a few trac sites for various projects and one of the sites already has plugins installed so I went there and and put the test plugin there and checked logs and it didn't work either. So I'm just going to conclude it's the plugin or something we already have in place and it's not me. I believe I'm going to try and make one and test it. Thanks for the help!
It sounds like you built the egg correctly. After you copy it into your plugins folder, change the file's owner and group (I'm assuming you're on Linux since you mentioned chmod) to match the account that your webserver uses. I'm not sure if that's strictly necessary, but it's what's always worked for me.
I may be misreading your #4, but it sounds like you copied the whole egg folder to your plugins directory. Only the .egg file needs to be copied over, it's a self-contained package. I don't think Trac looks for .egg files in subdirectories.
Restarting your webserver is the easiest way to restart Trac. Actually, I'm not aware of any other way to do it.
When it comes to plugin problems, Trac's log is usually a very good source of information. I recommend setting Trac's log level to DEBUG, then shut down the web server. Clear out the contents of Trac's log file, then start the web server and make a copy of Trac's log file after the server has completely come back online. Do this process twice: once with the plugin installed and once without it installed. The difference in the logfiles should give you a good indication of what the problem is. Once you get accustomed to what your logs normally look like, you'll be able to read the log in place without clearing it out and generating two versions of it.
By the way, what Trac version are you using?
Check the Trac version and downloaded plugin
instead python setup.py bdist_egg try python setup.py install
Quite an old thread, but since I ran into the same problem at one point:
Make sure you build the .egg with the same Python version that you use to run Trac with!Backwards compatibility between Python versions does not matter here, because Trac reads information about the Python version out of the .egg file before it even loads it, to make sure it is compatible.
(Small version numbers should not matter, so you should be able to run a .egg with Python 2.7.10 when it was built with 2.7.3, but not when it was built with 2.6.x. Look at the Version number that is written into the .egg file name.)