import sqlparse ModuleNotFoundError: No module named 'sqlparse' - python

I have installed
pip install sqlparse
pip3 install sqlparse
conda install sqlparse
But still getting sqlparse module error
Why is that?
(New4) C:\Users\zesha\Documents\GitHub\django-blog>python manage.py makemigrations
Traceback (most recent call last):
File "C:\Users\zesha\Documents\GitHub\django-blog\manage.py", line 21, in <module>
main()
File "C:\Users\zesha\Documents\GitHub\django-blog\manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\ProgramData\Miniconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\db\utils.py", line 214, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\db\utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "C:\ProgramData\Miniconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\db\backends\sqlite3\base.py", line 32, in <module>
from .introspection import DatabaseIntrospection # isort:skip
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\db\backends\sqlite3\introspection.py", line 4, in <module>
import sqlparse
ModuleNotFoundError: No module named 'sqlparse'
I am getting the following error.
I am not sure where should I install sqlparse

Since you also tried conda install, I am supsecting that you have anaconda or miniconda installed. pip and pip3 probably point to the python version managed by conda. However, your error message suggests that your script is being executed with a python version that is located at
C:\Users\zesha\AppData\Roaming\Python\Python39\
To install for that version of python specifically, you could try something like (might need to check that that is actual path to python.exe in that folder):
C:\Users\zesha\AppData\Roaming\Python\Python39\python.exe -m pip install sqlparse
Alternatively, run your script with the python that is managed by conda

Related

Can't run a specific django project in a virtualenv

I need to edit but first run this project: https://pagure.io/fedora-commops/fedora-happiness-packets and it gives me errors even though I followed the instructions.
First I forked the repo, then cloned it to my computer and I followed the instructions listed in the setup section of the README.md file. When I run the command ./manage.py collectstatic I get this error:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/virtualenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/virtualenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute
django.setup()
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/virtualenv/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/virtualenv/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/virtualenv/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/happinesspackets/messaging/models.py", line 15, in <module>
from happinesspackets.tasks import send_html_mail
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/happinesspackets/tasks.py", line 3, in <module>
from happinesspackets._celery import app
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/happinesspackets/_celery.py", line 2, in <module>
from celery import Celery
ImportError: No module named celery
I tried importing celery but that method didn't work and I don't want to mess with the project.
Looking at issue 49, it looks like celery is a dependency but it isn not listed in the requirements. Until that is fixed, you'll have to install it manually.
pip install celery
Have you done pip install -r requirements in the virtualenv ?

I am trying to connect my Django app with Mysql database but when I tried to migrate loads of error started to pop up in the terminal.

I tried various ways (every solution mentioned in the stackoverflow) to solve the problem but still the problems continues.
When I run : "python manage.py migrate" the following error is shown
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/management/base.py", line 305, in run_from_argv
self.execute(*args, **cmd_options)
File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/management/base.py", line 353, in execute
self.check()
File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/management/base.py", line 385, in check
include_deployment_checks=include_deployment_checks,
File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 61, in _run_checks
issues = run_checks(tags=[Tags.database])
File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/core/checks/database.py", line 9, in check_database_backends
for conn in connections.all():
File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/db/utils.py", line 226, in all
return [self[alias] for alias in self]
File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/db/utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/db/utils.py", line 115, in load_backend
return import_module('%s.base' % backend_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Manish/Projects/Websites/SanirTVNetwork/SanirTV/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 28, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
Then I tried: "pip install mysql-python" as per the suggestions in the stackoverflow similar questions. I got the following error
Collecting mysql-python
Using cached MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/7_/cx21vvvn5cqdypfndc7j_jl80000gn/T/pip-build-JjMQeR/mysql-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 53, in get_config
libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
File "setup_posix.py", line 8, in dequote
if s[0] in "\"'" and s[0] == s[-1]:
IndexError: string index out of range
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/7_/cx21vvvn5cqdypfndc7j_jl80000gn/T/pip-build-JjMQeR/mysql-python/
I even tried: "brew install mysql-connector-c" but the same error starts to come.
I finally did it:
First I installed the command line developer tools required by running the following code inside the virtualenv
$ xcode-select --install
Then I installed MySQL-python by using the following code
pip install MySQL-python
Finally I migrated the database using:
python manage.py migrate
It worked without any errors
The main problem with the error was that I didn't installed the command line developer tools required.

Error loading Mysqldb module in Python Django

I am currently working on Ubuntu 14.10/Python/Django/MySQL and encountering the following error when I try to run:
$python manage.py makemigrations polls
or
$python manage.py migrate polls
I have also tried syncdb
The error is:
(Aaronpythonenv)aaron#aaron-N550JK:~/mysite$ python manage.py makemigrations polls
Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/init.py", line 338, in execute_from_command_line
utility.execute()
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/init.py", line 312, in execute
django.setup()
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/init.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/contrib/auth/models.py", line 41, in
class Permission(models.Model):
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/base.py", line 139, in new
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/base.py", line 324, in add_to_class
value.contribute_to_class(cls, name)
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/options.py", line 250, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/init.py", line 36, in getattr
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/utils.py", line 240, in getitem
backend = load_backend(db['ENGINE'])
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/backends/mysql/base.py", line 27, in
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
I have used PIP to install mysql-python to my environment which I recieved another error. I then used sudo apt-get command to install correct the error PIP brought up.
massive thank you in advance please let me know if I need to add anything else.
I faced somewhat similar problem. Try these steps:
1). Upgrade pip to the latest version.
sudo pip install pip --upgrade
2). Build the dependencies for python-mysqldb libraries:
sudo apt-get build-dep python-mysqldb
3). Install the Python MySQL libraries:
sudo pip install MySQL-python
I think it means there is no module named mysqldb.
You just need to setup the mysqldb module.
For example if you use the ubuntu, you just need to run this command:
sudo apt-get install python-mysqldb
and then you problem will be fixed!

Installing psycopg2 in a virtualenv in ubuntu os

I using a virtualenv and I am trying to set up postgresql. I have psycopg2 installed on my system, but it appears that my virtual env does not recognize psycopg2. Is it possible to just copy the system wide psycopg2 files into my django project directory or is this a bad approach to take?
This is the relevant part of my settings.py file in my django project.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_db' ,
'USER': 'myusername' ,
'PASSWORD': 'mypassword' ,
'HOST': 'localhost' ,
'PORT': '' ,
}
}
When I run python manage.py migrate I get this error:
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/apps/config.py", line 197, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 40, in <module>
class Permission(models.Model):
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/db/models/base.py", line 125, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/db/models/base.py", line 300, in add_to_class
value.contribute_to_class(cls, name)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/db/models/options.py", line 166, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/db/__init__.py", line 40, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/db/utils.py", line 242, in __getitem__
backend = load_backend(db['ENGINE'])
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/db/utils.py", line 108, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 27, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2
When I do pip install psycopg2 in my virtual env, I get the following error:
Exception:
Traceback (most recent call last):
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/pip/commands/install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/pip/req.py", line 1153, in prepare_files
location = req_to_install.build_location(self.build_dir, not self.is_download)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/pip/req.py", line 218, in build_location
_make_build_dir(build_dir)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/pip/req.py", line 1527, in _make_build_dir
os.makedirs(build_dir)
File "/uwsgi-tutorial/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/uwsgi-tutorial/build'
Storing debug log for failure in /home/user/.pip/pip.log
This is an old thread but some people might experience Python.h not found type of error while pip-installing psycopg2 to virtualenv on Ubuntu based systems.
Check your virtualenv python version by running python -V inside virtualenv.
Assuming it is Python 3.8.0, try installing libpython3.8-dev to your system (not virtualenv) by:
sudo apt-get install libpython3.8-dev
Probably similar approach with other versions.
That solved it for me.
Based on the combination of your question and one of your comments, it appears that when you ran sudo pip install psycopg2, it was using the system install, as it referred to psycopg2 in /usr/lib/python2.7/dist-packages which is different from the environment from which you're trying to run Django.
Your permissions error, which is from the Django environment, seems likely to be due to not using sudo (among other things, some C compilation needs to take place, during the psycopg2 install, and so sudo is often required whereas it isn't with many other packages).
I would recommend you refer to the virtualenv install's pip binary explicitly when running the sudo command.
i.e.: sudo <virtualenv_root>/bin/pip install psycopg2
Something that worked for me (python 3.8 in virtualenv):
Inside the virtual environment type:
pip install psycopg2-binary
Best.

python django - no module psycopg2.extension even after installing compiled version psycopg2-2.4.5.win32-py2.7.‌exe

I am using python django on windows,and trying to deploy to heroku . When i tried to install psycopg2 using pip,
pip install psycopg2
i got error :
unable to find vcvarsall.bat
Then i found that i need to install visual studio 2008 (or) i can directly download and install compiled version , so downlaoded from this link :
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Filename i downloaded : psycopg2-2.4.5.win32-py2.7.‌exe
Even after installing this i am getting error : no module named psycopg2.extensions
So, what more should i do ?
D:\mycode\python\mysite>heroku run python manage.py syncdb
Running python manage.py syncdb attached to terminal... up, run.1
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/venv/lib/python2.7/site- packages/django/core/management/__i
nit__.py", line 443, in execute_from_command_line
utility.execute()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__i
nit__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__i
nit__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__i
nit__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/app/.heroku/venv/lib/python2.7/site-packages/django/utils/importlib.py"
, line 35, in import_module
__import__(name)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_
signal
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/sql
.py", line 6, in <module>
from django.db import models
File "/app/.heroku/venv/lib/python2.7/site- packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/utils.py", line92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/utils.py", line24, in load_backend
return import_module('.base', backend_name)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/utils/importlib.py"
, line 35, in import_module
__import__(name)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 13, in <module>
from django.db.backends.postgresql_psycopg2.creation import DatabaseCreation
File "/app/.heroku/venv/lib/python2.7/site- packages/django/db/backends/postgre
sql_psycopg2/creation.py", line 1, in <module>
import psycopg2.extensions
ImportError: No module named psycopg2.extensions
D:\mycode\python\mysite>
While isntalling psycopg2 both by pip and easy_install, installdidnt work as i got this error : unable to find vcvarsall.bat with some msg : no previsouly included directores matching 'doc\src_build'
Thanks
Despite some claims on the Internet, psycopg2 DOES work in a VirtualEnv.
Download the correct version of win-psycopg2. Typically I use 32-bit Python 2.7 so I got psycopg2-2.4.5.win32-py2.7-pg9.1.3-release.exe.
You CANNOT install this file into a VirtualEnv, but you can rename the .exe file to .zip and open with a utility like 7-Zip. You will get a folder called “psycopg2″ and a file called “psycopg2-2.4.5-py2.7.egg-info”. Copy these into:
[...]\Envs\MyVirtualEnv\Lib\site-packages
This worked for me, hope it works for you.
Take a look at http://slacy.com/blog/2010/09/python-unable-to-find-vcvarsall-bat/. It seems you need to install Microsoft Visual Studio Express to solve the vcvarsall.bat issue.
Pretty crazy...
Binaries from this link:
http://www.stickpeople.com/projects/python/win-psycopg/
In settings.py it should look like this in db settings
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
You CANNOT install this file into a VirtualEnv, but you can rename the .exe file to .zip and open with a utility like 7-Zip. You will get a folder called “psycopg2″ and a file called “psycopg2-2.4.5-py2.7.egg-info”. Copy these into:
[...]\Envs\MyVirtualEnv\Lib\site-packages
Yes, this work!

Categories

Resources