Python-Flask : Module not Found after Installation - python

I installed flask by the instructions on the page
http://flask.pocoo.org/docs/installation/#installation
Now, when I try
>>> import os
>>> from flask import Flask
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named flask
This means that os can be found whereas Flask cannot. How could you tell to python, where to find the needed modules?

Flask depends on two external libraries, Werkzeug and Jinja2.
you can check in your Lib\site-packages dir in windows or site-packages in other os whether you had installed it successfully
I think you should try to install it again.
it has no matter with the os module

Related

codeanywhere.com Python doesn't see virtualenv

I use codeanywhere.com try to create application with Python werkzeug and jinja2.
I install those library utilize virtualenv. Now I face the problem
Traceback (most recent call last):
File "manage.py", line 4, in
from werkzeug import Request
ImportError: No module named 'werkzeug'
virtualenv activated but nothing is works.
Does anybody has experience with codeanywhere.com?
Oh I solve this problem. In the container config file add instruction "source venv3/bin/activate" as shown on a picture add path to python as well.
enter image description here

ImportError when importing elasticsearch.helpers in Python

I am using a docker container with Ubuntu 16.04 Xenial with a Python 3.5.2 virtual environment. Every time I am trying to initialize the server uWSGI I am getting the following Python error:
File "/env/lib/python3.5/site-packages/elasticsearch_dsl/__init__.py", line 5, in <module>
from .search import Search
File "/env/lib/python3.5/site-packages/elasticsearch_dsl/search.py", line 3, in <module>
from elasticsearch.helpers import scan
ImportError: No module named 'elasticsearch.helpers'
I have been running the bash manually inside the docker container to see what is wrong with the module. By running pip list in the virtual environment I can tell that the packages are correctly installed:
# pip list
elasticsearch (2.1.0)
elasticsearch-dsl (0.0.8)
Running sys.path shows that the site packages folder was correctly added to the python path:
import sys
sys.path
[
'',
'/env/lib/python35.zip',
'/env/lib/python3.5',
'/env/lib/python3.5/plat-x86_64-linux-gnu',
'/env/lib/python3.5/lib-dynload',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/env/lib/python3.5/site-packages'
]
There is a __init__.py file within the folder elasticsearch.helpers so that's not the problem. If I try the import from the Python console it will fail as well:
from elasticsearch.helpers import scan
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'elasticsearch.helpers'
But now if I go to the site-packages folder cd /env/lib/python3.5/site-packages and run python console from here, the import will work.
I don't really know why this is happening any help will be appreciated.
ouch... just a rookie mistake. One of the folders of my project was called elasticsearch and that was causing the issue.
Running the following command I found out that my app was simply loading the elasticsearch module from a different location.
import elasticsearch
import pprint, os
pprint.pprint(os.path.abspath(elasticsearch.__file__))
# /var/sites/my_app/elasticsearch/__init__.py

Configure python model in xampp

I installed mod_python, I try to run python script like:
from mod_python import apache
It show me the error message:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
from mod_python import apache
File "D:\Python27\lib\mod_python\apache.py", line 55, in <module>
import _apache
ImportError: No module named _apache
I don't know why?
My enviroment:
Windows XP, Python 2.7.2
If you don't get any help here, try the mod_python mailing list:
http://www.modpython.org/live/mod_python-2.7.8/doc-html/installation.html
Its probably that the script location is not added to your path.
try:
import sys
sys.path
sys.path.append('/path/to/the/mod_python.py')
If this doesn't work, it was probably not installed correctly.
If you want to add it to your system path permanently so you don't have to use the code above every time check out this SO question.

Cannot import flask from project directory but works everywhere else

So I have run into a funny problem when trying to use Flask, I can only run it from ~/ (home) and not from ~/Projects/projectfolder. I'm using Python 2.7.4 installed via their homepage, virtualenv and virtualenvwrapper. Every time it's the same:
$ mkvirtualenv project
New python executable in project/bin/python
Installing setuptools............done.
Installing pip...............done.
Then I install Flask:
$ pip install flask
[...]
Successfully installed flask Werkzeug Jinja2
Cleaning up...
Then I open Python from my home directory:
(project) $ python
>>> from flask import Flask
>>>
Then I quit and go to my project folder:
(project) $ cd ~/Projects/example
(project) $ python
>>> from flask import Flask
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "flask.py", line 1, in <module>
from flask import Flask
ImportError: cannot import name Flask
And I'm a bit lost as to why this is happening, anybody have any ideas?
According to you traceback, you have a module of your own called flask.py in ~/Projects/example.
The current directory is searched before the actual package installation path, so it shadows the "real" Flask.

Python/django : Cannot import GeoIP

I cannot import GeoIP in django. I searched and tested this error two days, but still could not know problem.
Surely, I installed GeoDjango. I'm on MacOS 10.8
following is log by tested by django shell
from django.contrib.gis import geoip
module 'django.contrib.gis.geoip' from '/Library/Python/2.7/site-packages/django/contrib/gis/geoip/__init__.pyc'
it works. even I could find geoip class at Library/Python/2.7/site-packages/django/contrib/gis/geoip/base.py
from django.contrib.gis.geoip import geoip
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name geoip
I also add django.contrib.gis to setting.py. Even I could find geoip class at eclipse shortcut.
anyway, I tested one more thing in django shell.
from django.contrib.gis.geoip.base import GeoIP
Traceback (most recent call last):
File "", line 1, in
File "/Library/Python/2.7/site-packages/django/contrib/gis/geoip/base.py", line 6, in
from django.contrib.gis.geoip.libgeoip import GEOIP_SETTINGS
File "/Library/Python/2.7/site-packages/django/contrib/gis/geoip/libgeoip.py", line 22, in
if lib_path is None: raise GeoIPException('Could not find the GeoIP library (tried "%s"). '
NameError: name 'GeoIPException' is not defined
What I missing?
Is there any way to test my error?
It appears you need to install a C library in order to use GeoIP.
Here is a snippet from the file that is throwing that error.
# The shared library for the GeoIP C API. May be downloaded
# from http://www.maxmind.com/download/geoip/api/c/
if lib_path:
lib_name = None
else:
# TODO: Is this really the library name for Windows?
lib_name = 'GeoIP'
Once you have it installed somewhere you need to reference it in your settings.py
GEOIP_LIBRARY_PATH = '/whatever'
The library was trying to tell you this, but it seems that there is a bug that prevents it from raising the correct error. https://github.com/django/django/pull/103
Previously i was facing this issue : from django.contrib.gis.geoip import GeoIP ImportError: cannot import name GeoIP
which is solved when i install this package.
yum install GeoIP-devel -y
The error is caused by moving the virtual environment folder.
The solution is to create the environment again and reinstall the pygeoip library.

Categories

Resources