I am stuck trying to get an application via Apache web server. I keep getting the following error.
ImportError: No module named flask
I believe this is because it might be pointing to the wrong Python. I had anaconda, but have removed that. When I check to see all the versions of Python, the following show up.
which -a python
/usr/local/bin/python
/usr/bin/python
Error: No module named flask
When I print the environment variables, here is the following:
printenv
PYTHONPATH=/usr/local/lib/python2.7/site-packages
The packages are all there as I have verified that with a pip freeze. Any help would be greatly appreciated as I have been stuck on this for a while. Thanks!
Your problem is quiet unclear answering from what i understood.
It seems like you have 2 python installed on your device. First find for which python all the modules are installed . Then simply mention the path of that python on the top of your script. If your case
#!/usr/bin/env python
or
#!/usr/local/env python
Related
django works well on my local machine. But, when I deploy it to heroku, I see "ModuleNotFoundError" "No module named '_tkinter'". Though, I never imported "_tkinter" or "tkinter" in my code. Your help will be appreciated. Thank you.
ModuleNotFoundError at /
No module named '_tkinter'
Request Method: GET
Request URL: https://howididit.herokuapp.com/
Django Version: 4.0.6
Exception Type: ModuleNotFoundError
Exception Value:
No module named '_tkinter'
Exception Location: /app/.heroku/python/lib/python3.10/tkinter/init.py, line 37, in
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.10.5
Python Path:
['/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python310.zip',
'/app/.heroku/python/lib/python3.10',
'/app/.heroku/python/lib/python3.10/lib-dynload',
'/app/.heroku/python/lib/python3.10/site-packages']
If you don't use Tkinter, just remove it from /forms.py. otherwise it'll be imported.
If you want to use tkinter,then consider the below process
please try adding tkinter to your requirements.txt. If it fails, even after that, check if you have added Python buildpack. If both the cases pass, try shelling into your Heroku instances and run the following command:
sudo apt install python3-tk
This will install Tkinter library in your instance of Heroku. That will resolve your error.
I found out these from pyexpat import model from turtle import title from attr import fields where imported in my forms.py. After deleting them, The problem was solved. Again, thank you all guys for your time, I really appreciate it.
Okay so for anyone looking at this in the future and banging their head against the desk...this is what worked for me:
I started with a new Hello World app and started adding bits of my original code until i got to the error
found out that one of the modules I was using : icu, was using tkinter and i needed to install the Pyicu module instead
pip installed directly into heroku bash console instead of through my app
None of the answers i found online had worked for me, and I think its because this error isnt from having tkinter directly in your app, but from another module thats calling it.
When in doubt do what I did and start a new project from scratch and add chunks of code until you get the error to see which module is creating it
Dont forget to change DEBUG to False in your settings file
I have had this problem for months. every time that I want to get a new python package and use it I get this error in terminal:
ImportError: No module named site
I don't know why do I get this error. actually, I can't use any new package because every time that I wanna install one I get this error. I searched and I found out that the problem would be for PYTHONPATH and PYTHONHOME but I don't know what they are and how can I change them.
My operating system is mac os and I don't know how to solve this problem in mac.
every time that I open the terminal I use these two commands to solve the problem:
unset PYTHONHOME
unset PYTHONPATH
but the next time I get the error again.
The Python tooling is evolving in Mac OS X such that Python 2.7 is being deprecated. System default paths may no longer apply as I learned after upgrading to Mac OS X Catalina (10.15.x). There are a few scenarios here:
GENERIC FIX -- According to this primer on the site package and Python internal paths, Python 2.7 requires a specific user path for site packages. The solution I settled on was simply this:
mkdir -p ~/.local/lib/python2.7/site-packages
At that point you will have a dedicated directory for Python modules (for Python to function). (NOTE that the error ImportError: No module named site is misleading as it really indicates that the correct directory structure didn't exist to allow the site module to properly load.)
BASIC ALTERNATIVE -- Is your PYTHONHOME pointing to Python3 and your python --version reporting 2.7? Does python3 --version report something different (or work at all)? This error started happening for me after the Catalina upgrade when I was trying to use built-ins. Check your .profile and .bash_profile to see if they are explicitly setting a custom PYTHONHOME and/or PYTHONPATH. One option is to change that so the ENV variables are set explicitly and manually only when a newer Python is needed. You may consider symlinking python3 and pip3 to leave the standard commands to the OS.
DEBUGGING -- If you would like to test and/or get more information, try executing Python in one of the increasingly verbose modes:
python -v
python -vv
python -vvv
I'm running a code on deep learning, which uses the opencv module, by running python main.py (contains import cv2 statement), but always get the error 'ImportError: dynamic module does not define module export function (PyInit_cv2)'.
I've tried to reinstall my anaconda and create new virtual environments, but all got the same result. This problem really confuses me a lot and I've googled for many related problems, none of them works. I think the problem is something related to the environment and has nothing to do with the code, because I got the same result by simply run import cv2 in python prompt. The more confusing thing is that, even after I remove the opencv module, I also get the same problem, but not a ModuleNotFoundError. Does anyone can give me some advice? Thanks a lot!
I think I found one possible reason of this error.
Recently I was configuring the caffe environment on one server, I downloaded the source code of opencv-2.4.13 and compiled manually, added /usr/local/opencv-2.4.13/build/lib to $PYTHONPATH, and caffe worked well. After that, when I entered one of my virtual environment using conda activate py35, which uses python3.5, tried import cv2 in the python prompt, got the error above.
I'm not sure but I think the cause of the error is opencv-2.4.13 compiles a python2 interface so it can't be imported by python3. Python imports packages by searching the directories listed in sys.path, where $PYTHONPATH is in the second place after the current working directory (This is a great article introduces the mechanism of python finding packages). So when we enter the py35 environment, python will first look for $PYTHONPATH and find the opencv installed on the root directory instead of finding the opencv in the virtual environment using conda install opencv-python.
So there are two solutions of this problem:
Use python2 instead.
Remove /usr/local/opencv-2.4.13/build/lib from $PYTHONPATH.
which all work for me.
Similar post, might help:
ImportError: dynamic module does not define init function (initfizzbuzz)
Could you provide info on how you installed the CV module?
I had the same problem, which was caused by the cv2.so file in /usr/local/lib/python2.7/site-packages/cv2.so. After I deleted the file and use command sudo pip3 install opencv-python, it worked for python3.
I've installed mesos 0.26 successfully on a vm machine.
The installation has been performed on an ubuntu trusty thar system
by following this manual:
https://open.mesosphere.com/getting-started/install/
So far so good. I wanted to write a tiny python framwork.
For this I need to install the eggs via easy_install:
(I've downloaded the eggs accordingly for the trusty thar ubuntu and the 0.26 mesos):
wget http://downloads.mesosphere.io/master/ubuntu/14.04/mesos-0.26.0-py2.7-linux-x86_64.egg
easy_install mesos-0.26.0-py2.7-linux-x86_64.egg
all went fine, however, if I start python in the shell
and type in
import mesos.interface
I get the message: ImportError: No module named interface
As someone suggested, it may be that there is no longer a binding for python, or that they have renamed the API calls. Well, I looked in the version updates here:
http://mesos.apache.org/documentation/latest/upgrades/
Since the transition from 0.19.x to 0.20.x there hasn't been any changes regarding the mesos.interface part, or at least they are not mentioning it here.
To increase the confusion I also get the following error message when I'm typing in python: import mesos.native
There I receive: ImportError: No module named interface.mesos_pb2. To put it into a nutshell: what is going wrong here, and how can it be fixed? And yes, I've googled various web pages, with terms such as "mesos python bindings", mesos +api +python, etc. And yes, I have also consulted the official mesos webpage. There are nice refences for Java and C++ but not for python, or at least they are very well hidden.
Thanks in advance for any hints.
Solved. For what reasons ever:
export PYTHONPATH=${PYTHONPATH}:/usr/lib/python2.7/site-packages/
is required to set the PYTHONPATH. After that step it works like a charm.
I'm new to python and have a little experience with VS, C# and WPF.
My question might seem similar to some asked questions, but I tried several of the suggested solutions (that worked for others), and yet it doesn't work for me.
I'm trying to build a simple WPF application that will send http requests.
The solution structure is as follows:
Solution MyApp
Project 1 <This is the startup project>
GUImodul.py
queryStringBuilder.py
<This project uses IronPython env for the WPF support>
Project 2
QuerySender.py (includes two classes)
<This project uses Python 3.4 env, only in this one I managed installing the "requests" package which I need for sending the query>
When I try to run this I get an error "No module named ndg.httpsclient.ssl_peer_verification", even though I only import from project 2 a class that doesn't contain any import from "requests" (it only creates an instance of the other class there that does have such import).
When I try to install ndg-httpsclient using pip, I get "Command python setup.py egg_info failed with error code 1".
Things I tried so far:
Adding "-X:FullFrames" to the debug properties of both projects
(re)installing steuptools with from ez_setup.zip
As said - ndg-httpsclient is installed for Python34
Using the "import requests" command only within the class NOT imported to Project1 (the one with IronPython env)
Tried installing a newer(?) version of urllib3
So...
I just might be doing something fundamentally wrong in this solution, which in this case I wish someone to help me understand what it is.
Otherwise, any idea what can I try next to make this thing work?
If you read the fine print, ndg-httpsclient is incompatible with Python 3, as it was developed for Python2.7 . That's probabably the root cause.
RE: Why is Python 3.0 not backward compatible?