Django Black Not Installing Properly in Pipenv environment - python

I received an error after installing Django Black. I ran pipenv install black --pre. Then when I ran manage.py runserver, I received the error below. Note that I am running Windows 10.
from custom_storages import MediaStorage
File "C:\Users\dgold2\Documents\py\ibankai\src\custom_storages.py", line 2, in <module>
from storages.backends.s3boto3 import S3Boto3Storage
File "C:\Users\dgold2\Documents\py\ibankai\src\.venv\lib\site-packages\storages\backends\s3boto3.py", line 18, in <module>
from django.utils.six.moves.urllib import parse as urlparse
ModuleNotFoundError: No module named 'django.utils.six'

I ran into this when I was using a template for Django + Vue on Heroku, the only difference being that in my case the error was thrown by whitenoise, a static files middleware, rather than s3boto3. The root cause is that my Pipfile specified Django = "*" but whitenoise = "==4.0". So pipenv was grabbing the most recent available Django, which was 3.0, but whitenoise 4 was trying to import from django.utils.six (like your s3boto3 package), which seems to have been deprecated in Django 3. (Compare 2.2, 3.0).
See if there's a s3boto3 version specifier in your Pipfile that you can update, or alternatively specify Django ="2.2" if you're willing to hold off on Django 3.

Related

I have a Django Question regarding the command line regarding running python manage.py test

I got this error when I was running the command python manage.py test in the absolute pathname
C:\Users\vitorfs\Development\myproject\myproject on the command line which I opened by selecting Run as Admin on Windows. In boards.py, I have the following
from django.core.urlresolvers import reverse
from django.test import TestCase
class HomeTests(TestCase):
def test_home_view_status_code(self):
url = reverse('home')
response = self.client.get(url)
self.assertEquals(response.status_code, 200)
This is the errors I'm getting:
1. Failed to import test module: board.tests. 2. ModuleNotFoundError: No module named django.core.urls
I am having trouble fixing the error. I followed the tutorial on Django at https://simpleisbetterthancomplex.com/series/2017/09/11/a-complete-beginners-guide-to-django-part-2.html
Can you show me what this means and help me fix this error?
Just to let you know, I'm learning Python and Django for fun.
Reinstalling django is only option because your core utilities are broken
Follow These Steps:
In Your Command prompt- pip uninstall django
In Your Command prompt- pip install django==2.7 # Assuming That You've django 2.7
Maybe This Would Help, Let Me Know If There Are Any More Problems I'am up for you!

cannot import name 'colored' from 'termcolor' [duplicate]

I am trying to start learning python bottle framework, I've installed python 2.7.11, and installed pip too, I've installed bottle using
pip install bottle
Collecting bottle
Using cached bottle-0.12.9.tar.gz
Installing collected packages: bottle
Running setup.py install for bottle ... done
Successfully installed bottle-0.12.9
Now I tried to run the example code from bottle website
from bottle import route, run, template
#route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
run(host='localhost', port=8080)
when I run this code it throws the following error
Traceback (most recent call last):
File "C:/Users/SID/Desktop/bottle.py", line 1, in <module>
from bottle import route, run, template
File "C:/Users/SID/Desktop\bottle.py", line 1, in <module>
from bottle import route, run, template
ImportError: cannot import name route
I don't know what went wrong could some one guide me, Is it the error with the code? or in bottle installation?
Note: I Tried python 3.4.3 too still facing same error while running program and I'm using windows 8.1 in virtual box
You have bottle.py file within your project folder. Problem occurred because python module C:/Users/SID/Desktop/bottle.py shadowed bottle.py module which installed by pip. Rename file which shadow real bottle.py module to fix import problem.
Location of file which shall be renamed is C:/Users/SID/Desktop/bottle.py.
When a module named bottle is imported, the interpreter first searches for a built-in module with that name. If not found, as in this case it then searches for a file named bottle.py in a list of directories given by the variable sys.path. sys.path is initialized from these locations:
the directory containing the input script (or the current directory).
PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
the installation-dependent default.
Make sure bottle is in PYTHONPATH. More info on PYTHONPATH here

Django 2.1 startproject throws weird error

I am trying to start my first app in Django 2.1 on Python 3.4. It's the first time with this versions, previously I worked only with Django 1.10 and Python 2.7. Everything on Ubunutu 14.04
I created a virtualenv, mostly following this tutorial: https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-local-programming-environment-on-ubuntu-16-04
However with slight changes of my own because first a locale issue appeared and was fixed like this:
sudo locale-gen "en_US.UTF-8"
Afterwards I changed the aliases like this:
alias python=python3
alias pip=pip3
That's all. After installing django==2.1 and runing:
django-admin.py start project myproject
This error appeared:
Traceback (most recent call last):
File "/home/ubuntu/workspace/skw/bin/django-admin", line 7, in <module>
from django.core.management import execute_from_command_line
File "/home/ubuntu/workspace/skw/lib/python3.4/site-packages/django/core/management/__init__.py", line 11, in <module>
from django.conf import settings
File "/home/ubuntu/workspace/skw/lib/python3.4/site-packages/django/conf/__init__.py", line 18, in <module>
from django.utils.functional import LazyObject, empty
File "/home/ubuntu/workspace/skw/lib/python3.4/site-packages/django/utils/functional.py", line 12
return _curried_func(*args, *moreargs, **{**kwargs, **morekwargs})
^
Inside this file functional.py in django my lint is showing a syntax error exactly at the line 12 ... but not sure if that's relevant, since I didn't change the syntax to python3 yet.
Because of this I can not start a new project, how to solve this?
EDIT:
It seems like it would run in Python2 not 3. However when I tried this:
python3 path/bin/django-admin.py startproject myproject
The result was exactly the same. I also did this with python3.4, still the same. Meanwhile it's been couple of hours and around 6 workspaces created and deleted. This probably is something basic that I am too tired to see but what?
python -V
Python 3.4.3
python3 -V
Python 3.4.3
python3.4 -V
Python 3.4.3
When looking into python-v, django import work no problem.
Django 2.1 is not supported on Python 3.4 - only 3.5, 3.6, and 3.7.
Release notes: https://docs.djangoproject.com/en/2.1/releases/2.1/
The python version you use is 3.4.3. But django==2.1 will install Django 2.1.
Django 2.1 supports Python 3.5, 3.6, and 3.7. Django 2.0 is the last version to support Python 3.4. We highly recommend and only officially support the latest release of each series.
Source Django 2.1 release notes
So, You need to install to resolve it
pip3 install Django==2.0.0

How to resolve cannot import name pages (django/wagtail)

Recently I have been trying to get wagtail to work with my existing Django application. I was experiencing an error: -
ImportError: No module named wagtail
unable to load app 0 (mountpoint='') (callable not found or import error)
After much troubleshooting I managed to fix this, by copying the folder wagtail from:
/usr/local/lib/python2.7/dist-packages/
into here
/opt/django/src/
Having resolved this error, I received another about a different module, and another... each time I copied the folder from /usr/local/lib/python2.7/dist-packages/ into /opt/django/src/ and it eventually resolved the issues I was having and uWSGI started.
Now when I access the homepage of my app, I receive this error
ImportError at /
cannot import name pages
Request Method: GET
Request URL: http://example.com
Django Version: 1.9
Exception Type: ImportError
Exception Value:
cannot import name pages
Exception Location: ./wagtail/wagtailadmin/urls/__init__.py in <module>, line 4
Python Executable: /usr/local/bin/uwsgi
Python Version: 2.7.3
Python Path:
['.',
'',
'/opt/django/src',
'/root/.python',
'/opt/django/env/lib/python2.7',
'/opt/django/env/lib/python2.7/plat-linux2',
'/opt/django/env/lib/python2.7/lib-tk',
'/opt/django/env/lib/python2.7/lib-old',
'/opt/django/env/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/opt/django/env/local/lib/python2.7/site-packages',
'/opt/django/env/lib/python2.7/site-packages']
I have checked the file referenced (./wagtail/wagtailadmin/urls/__init__.py) and it looks like this:
from django.conf.urls import url, include
from django.views.decorators.cache import cache_control
from wagtail.wagtailadmin.urls import pages as wagtailadmin_pages_urls
from wagtail.wagtailadmin.urls import collections as wagtailadmin_collections_urls
from wagtail.wagtailadmin.urls import password_reset as wagtailadmin_password_reset_urls
from wagtail.wagtailadmin.views import account, chooser, home, pages, tags, userbar
from wagtail.wagtailadmin.api import urls as api_urls
from wagtail.wagtailcore import hooks
from wagtail.utils.urlpatterns import decorate_urlpatterns
from wagtail.wagtailadmin.decorators import require_admin_access
The offending line is the first wagtail 'from' ...
from wagtail.wagtailadmin.urls import pages as wagtailadmin_pages_urls
How can I resolve this error?
I've ran a few tests on wagtail setup. I made each test in a fresh Ubuntu 14 install (each test in a new workspace on Cloud9 IDE).
Test 1: Straight python 2.7
sudo pip install wagtail
ERRO: error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Comment: Lots of x86_64-linux-gnu-gcc: error: build/temp.linux-x86_64-2.7/libImaging/codec_fd.o: No such file or directory errors were output.
Didn't work.
Test 2 - Python 2.7 with virtualenv
sudo pip install virtualenv
virtualenv env
source env/bin/activate
Now from their github https://github.com/wagtail/wagtail
pip install wagtail
out: Successfully installed Django-1.10.7 Pillow-4.1.1 Unidecode-0.4.20 Willow-0.4 beautifulsoup4-4.5.3 django-modelcluster-3.1 django-taggit-0.22.1 django-treebeard-4.1.0 djangorestframework-3.6.2 html5lib-0.999999999 olefile-0.44 pytz-2017.2 requests-2.13.0 wagtail-1.9.1 webencodings-0.5.1
wagtail start mysite
cd mysite
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
I had to edit the settings/dev.py and include ALLOWED_HOSTS = ['*'] because I'm on cloud 9. Also needed the $IP:$PORT after runserver. WORKED!
Test3 - Python 3.4 with virtualenv
sudo pip3 install virtualenv
virtualenv -p python3 env
source env/bin/activate
pip install wagtail
Successfully installed Django-1.10.7 Pillow-4.1.1 Unidecode-0.4.20 Willow-0.4 beautifulsoup4-4.5.3 django-modelcluster-3.1 django-taggit-0.22.1 django-treebeard-4.1.0 djangorestframework-3.6.2 html5lib-0.999999999 olefile-0.44 pytz-2017.2 requests-2.13.0 wagtail-1.9.1 webencodings-0.5.1
Rest of the command are the same. And it WORKED!
Test 4 - Python 3.4 no virtualenv
sudo pip3 install wagtail
out: Successfully installed wagtail django-taggit requests Unidecode Django djangorestframework Pillow beautifulsoup4 Willow django-modelcluster django-treebeard olefile pytz
wagtail start mysite
python3 manage.py migrate
python3 manage.py createsuperuser
python3 manage.py runserver
EDIT: Made a mistake. Should've run with python3, not python in this case. Did it again and worked!
Conclusion: Looks that you need a virtualenv for this to work on Ubuntu 14 and python2. With python3 it works with and without virtualenv. I could not reproduce your error, but the idea is the same: it does not work because it looks for stuff in the wrong place.
Comments: There are two things you mention that I could not test:
I have been trying to get wagtail to work with my existing Django
application
With this big amount of heavy dependencies, (Pillow, Django rest, beatifullsoup and others I've never heard of) it would be strange if it worked out of the box with a previous setup. I mean, Django is a dependency for wagtail. So I would try the other way around. Start fresh with wagtail and port your code there (with python3 for the sake of the community ;) ). Also this manual copy of files is like programmers worst nightmare (at least to me). This looks like a version problem. Try to post the versions of everything involved, and the exact steps to reproduce the issue. I mean, did you pip install wagtail in the operating system that django was running?
I was having and uWSGI started.
So you have your app deployed already? This complicates things. If versions and virtualenv do not solve your problem, community needs setup details of deploy. Also you haven't mentioned your operational system.
I hope this helps! Good Luck!
I ran into the
cannot import name pages
error at:
from wagtail.wagtailadmin.urls import pages as wagtailadmin_pages_urls
while trying to deploy a wagtail app to Google App Engine and could not duplicate the problem on my local dev server.
A seemingly unrelated error that I saw only intermittently in GAE involved an import error in the PIL library. I was able to resolve BOTH errors by deleting PIL and pillow related folders from my vendored packages in my /lib directory. I had to import PIL through the app.yaml file instead due to the platform specific binary, but running pip install -t lib/ -r requirements-vendor.txt caused PIL to be installed into the lib folder as well (as a dependency of Wagtail)

No module named django urls for any django-admin command

I'm having trouble running Django on my company's server. When I try to start a project, like django-admin startproject newproject, it gives me:
File "/opt/packages/anaconda/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
from django.urls import set_script_prefix
ImportError: No module named urls
When I run python and import django; django.VERSION, I get (1, 10, 2, u'final', 0). (I recently downgraded to 1.9.5 to match my company's version).
And of course the company runs 1.9.5 from which I checked from pip list. Shouldn't I get 1.9.5 also when I call for the version in python?
Here is my profile also:
python='/opt/packages/anaconda/bin/python'
export PATH=/opt/packages/anaconda/bin:$PATH
export LD_LIBRARY_PATH=/opt/packages/anaconda/lib:$LD_LIBRARY_PATH
export TCL_LIBRARY=/opt/packages/anaconda/lib/tcl8.5

Categories