ImportError: No module named tablib - python

I am using "flask+nginx+uwsgi" for my website. Everything works fine at first.Then in order to transform my *.txt file to excel format, I install tablib in my environment and add just "import tablib" into my init.py , then I cannot access my website any more. Once I comment out "import tablib", it works again. And I notice the uwsgi.log, it tells me that:
> *** Operational MODE: preforking *** Traceback (most recent call last): File "./__init__.py", line 14, in <module>
> import tablib ImportError: No module named tablib unable to load app 0 (mountpoint='') (callable not found or import error)
> *** no app loaded. going in full dynamic mode ***
I check uwsgi setting carefully and i don't think it's uwsgi that create this error(because whenever I remove "import tablib", everything works perfectly). I also checked the installation of tablib, it was installed successfully. Can anyone give me a suggestion on how to fix this error? thanks a lot!

Are you running uwsgi as root? If so, running sudo -H pip install tablib in terminal should fix the issue for you. It is possible that you have installed tablib in your own profile, but not in the root profile.

Related

flask.cli.NoAppException: Application crashing

My Flask Application is crashing when I'm trying to access it.
This is similar error to this or this. However, my set-up seems correct.
flask.cli.NoAppException: The file/path provided (server) does not appear to exist. Please verify the path is correct. If app is not on PYTHONPATH, ensure the extension is .py
My environment variable correctly set.
export FLASK_APP=server.py
export FLASK_DEBUG=1
My server file is server.py, and I don't have any __init__.py in the directory.
I don't recall having change anything special in the code. Where does the bug could come from?
The issue was that some package were missing or corrupted.
I reinstalled everything with pip3 install -r requirements.txt --ignore-installed and now it works fine.
This error may be a sign that an import is not found.
To see which import is missing, try to run your server.py file with the python interpreter:
python yourapp.py
Example of output :
Traceback (most recent call last):
File "yourapp.py", line 4, in <module>
from flask_httpauth import HTTPBasicAuth
ImportError: No module named flask_httpauth
Source (and other leads)
For me, solution was fixing a misspelled function name "create_app" in my _ init _.py
from flask import Flask
def create_app(test_config=None):
app = Flask(__name__)
return app
Super late answer, but I just ran into this and the solution was to use a Remote WSL connection in VS Code. I thought I was in the correct folder, but VS Code was looking at a very similar folder in Windows. You can tell you're in the wrong folder by running "touch somefile.abc" in your linux terminal, from the project folder, but that file doesn't automatically appear in VS Code's folder structure.
https://code.visualstudio.com/docs/setup/linux
https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl

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

Problems with fastcgi when installing Django on Justhost

I am following the following tutorial at http://flailingmonkey.com/install-django-justhost/ to install Django on my Justhost web server. So far I have managed to install Django and Python on my Justhost shared web server.
However, I am now stuck when trying to configure my new site. Every time I run the command: python mysite.fcgi I keep getting the following error message:
Traceback (most recent call last):
File "mysite.fcgi", line 9, in <module>
from django.core.servers.fastcgi import runfastcgi
ImportError: No module named fastcgi
Content of mysite.fcgi
#!/home4/xxxxx/python/bin/python
import sys, os
# Where /home/your_username is the path to your home directory
sys.path.insert(0, "/home4/xxxxx/python")
sys.path.insert(13, "/home4/xxxxx/public_html/django-project/admin")
os.environ['DJANGO_SETTINGS_MODULE'] = 'admin.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
How do I fix it?
I had the exact same issue. Heres how to solve it
load up your ssh client
cd ~/
pip install django==1.8.7
pip install flup==1.0.2
and you should be good
If you need FastCGI support for Django version 1.9 or higher, see https://github.com/NetAngels/django-fastcgi. You still need to install flup separately as #dvicemuse advised.
Also, official Django version 1.8 FastCGI docs may help, see https://docs.djangoproject.com/en/1.8/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-with-apache

Pip shows package installed, python says it is not

I am trying to write a python script that includes import requests. I have already installed it using pip install requests and a pip freeze shows the results below:
[rhanthony#python1 ~]$ pip freeze
--snip--
requests==2.8.1
--snip--
[rhanthony#python1 ~]$
This to me looks like it should be installed and working, however when I run my application with uswgi -http 0.0.0.0:80 --wsgi-file app.py, I get the following:
*** Operational MODE: single process ***
Traceback (most recent call last):
File "piql.py", line 2, in <module>
import requests
ImportError: No module named requests
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
What am I missing here?
This whole virtual machine was cursed. There were apparently a ton of odd dependency breaks all over, and other nonsense. Instead of working this problem further, and then moving on to countless others, the machine was scrapped and re-rolled. Issue did not return.

Django installation has no __init__.py in django.core

I have a ubuntu lucid VPS server where I try to run my django development server.
Running python manage.py runserver gives me the following error:
Traceback (most recent call last):
File "manage.py", line 2, in <module>
from django.core.management import execute_manager
ImportError: No module named core.management
I can import django without any problem in a python shell. I looked in the django install directory and noticed there is no \__init__.py in the django/core folder. Which I beleive is the source of the problem for python to register django.core as a module.
It then looks like an installation issue. I installed django using apt-get.
FYI the django install worked perfectly on my home computer with same OS.
Any ideas?
solved.
Thank you for all the suggestions. I installed django using the tar ball as instructed in the django website.
apt-get is not a good idea to install django. I also had to manually remove the left over django folder in /usr/lib/pymodules/python2.6 after using apt-get remove.

Categories

Resources