Having Issues with Django on Windows Vista - django

I installed subversion, which seemed to install Python25, which my computer won't let me erase, or even recognize as a program on the control panel. I copied my Python27 Python.py file into the Python 25 folder to replace Python.py (the Python 25 version), and got my command prompt to run Python 27 (even though I had specified the Python 27 folder, it insisted on running Python 25). I copied the Django trunk into the site-packages of Django 27 and Django 25. Import Django works in Python, but now I'm getting this error:
C:\Windows\system32>cd C:\Users\Susan\Documents\practice
C:\Users\Susan\Documents\practice>django-admin.py startproject mysite
Traceback (most recent call last):
File "C:\csvn\Python25\django-admin.py", line 2, in <module>
from django.core import management
File "C:\csvn\Python25\lib\site-packages\django\core\management\__init__.py",
line 7, in <module>
from django.core.management.base import BaseCommand, CommandError, handle_de
fault_options
File "C:\csvn\Python25\lib\site-packages\django\core\management\base.py", line
14, in <module>
from django.utils.encoding import smart_str
File "C:\csvn\Python25\lib\site-packages\django\utils\encoding.py", line 2, in
<module>
import urllib
File "C:\csvn\Python25\lib\urllib.py", line 26, in <module>
import socket
File "C:\csvn\Python25\lib\socket.py", line 45, in <module>
import _socket
ImportError: Module use of python25.dll conflicts with this version of Python.
Thanks in advance.
Oh, and this is my environment path variable: C:\Program Files\SSH Communications Security\SSH Secure Shell;C:\Python27;C\Python27\scripts;C:\Python27\Lib\site-packages\django\bin\
And this is my python variable: C:\Python27;C\Python27\scripts;C:\Python27\Lib\site-packages\django\bin\
EDIT: realized that USER path wasn't the same as System path. Made them both the same, now receiving this message:
C:\Users\Susan\Documents\practice>django-admin.py startproject mysite
Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\django\django\bin\django-admin.py", line 2
, in <module>
from django.core import management
File "C:\csvn\Python25\lib\site-packages\django\core\management\__init__.py",
line 7, in <module>
from django.core.management.base import BaseCommand, CommandError, handle_de
fault_options
File "C:\csvn\Python25\lib\site-packages\django\core\management\base.py", line
14, in <module>
from django.utils.encoding import smart_str
File "C:\csvn\Python25\lib\site-packages\django\utils\encoding.py", line 2, in
<module>
import urllib
File "C:\csvn\Python25\lib\urllib.py", line 26, in <module>
import socket
File "C:\csvn\Python25\lib\socket.py", line 45, in <module>
import _socket
ImportError: DLL load failed: The specified module could not be found.
Why does it keep trying to use Python25?

I would un-install Python 2.7 and 2.5 from your machine and re-inistall Python 2.7. You'll have to have a working Python install before you can think about installing Django.
After that's working, I would recommend installing virtualenv and Justin Driscoll's virtualenv helper for Windows.
Virtualenv allows you to create different Python runtimes so you don't have to install modules directly into the system Python Path. Installing virtualenv gets you pip, which you can use to install modules like Django, into your virtualenv's site-packages folder.

Related

ctypes init fails using local app engine, django and virtualenv with python 2.7

I'm facing an issue with the init of ctypes
if int(_os.uname()[2].split('.')[0]) < 8:
ValueError: invalid literal for int() with base 10: '
My app is written in Python 2.7 and based on Django, running locally using App Engine SDK and virtualenv. It's been in production for a long time and is running successfully locally on other machines. Meaning this is a local issue for my machine. I'm on Mac OSX 10.15.3 Catalina.
The issues arises when I'm loading any page of my app, after starting the app engine local development server. The App Engine server is starting successfully (I can access the app engine admin webpag), but the above exception is being raised (see callstack below), as it seems os.uname() is returning an invalid value.
When running os.uname() myself, the result seems legit. Both when the virtualenv is activated or using the os/pyenv python interpeter.
Python 2.7.15 (default, Mar 15 2020, 22:00:51)
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.uname()[2].split('.')[0]
'19'
Solutions I've tried:
Calling os.uname() inside and outside of the virtualenv, it works correctly.
Creating a virtualenv using the system Python 2.7.17 installation
Creating a virtualenvs using pyenv with 3 different python 2 versions (2.7.17, 2.7.16, 2.7.15)
Looking at the full callstack, it seems that ctypes init is being called from the interpeter outside of the virtualenv. This is true both if I'm using the OS's python or the pyenv python when creating the virtualenv. Maybe it's not finding ctypes in the virtualenv?
Traceback (most recent call last):
File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 358, in __getattr__
self._update_configs()
File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 294, in _update_configs
self._registry.initialize()
File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 165, in initialize
import_func(self._modname)
File "/Users/myuser/.pyenv/versions/2.7.15/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/myuser/git/myproject/appengine_config.py", line 38, in <module>
cloud_sql_conn_retry.monkey_patch_mysql_backend()
File "/Users/myuser/git/myproject/server/utils/cloud_sql_conn_retry.py", line 14, in monkey_patch_mysql_backend
from django.db.backends.mysql.base import DatabaseWrapper
File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 38, in <module>
from .creation import DatabaseCreation # isort:skip
File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/db/backends/mysql/creation.py", line 4, in <module>
from django.db.backends.base.creation import BaseDatabaseCreation
File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 5, in <module>
from django.core import serializers
File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/core/serializers/__init__.py", line 23, in <module>
from django.core.serializers.base import SerializerDoesNotExist
File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/core/serializers/base.py", line 4, in <module>
from django.db import models
File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/db/models/__init__.py", line 3, in <module>
from django.db.models.aggregates import * # NOQA
File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/db/models/aggregates.py", line 5, in <module>
from django.db.models.expressions import Func, Star
File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/db/models/expressions.py", line 6, in <module>
from django.db.models import fields
File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 14, in <module>
from django import forms
File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/forms/__init__.py", line 7, in <module>
from django.forms.fields import * # NOQA
File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/forms/fields.py", line 17, in <module>
from django.core import validators
File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/core/validators.py", line 507, in <module>
allowed_extensions=get_available_image_extensions(),
File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/django/core/validators.py", line 498, in get_available_image_extensions
from PIL import Image
File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/PIL/Image.py", line 134, in <module>
from pathlib2 import Path
File "/Users/myuser/git/myproject/env/lib/python2.7/site-packages/pathlib2/__init__.py", line 5, in <module>
import ctypes
File "/Users/myuser/.pyenv/versions/2.7.15/lib/python2.7/ctypes/__init__.py", line 29, in <module>
if int(_os.uname()[2].split('.')[0]) < 8:
ValueError: invalid literal for int() with base 10: ''
Also, when importing ctypes in python shell, it's all working. Here is the paths of libraries that are imported while inside the virtual env. ctypes and os are imported from the pyenv interpeter, and django is imported from the virtualenv python. It's not clear to me why, and I suspect this might be related to the issue.
>>> import ctypes
>>> print(ctypes)
<module 'ctypes' from '/Users/myuser/.pyenv/versions/2.7.15/lib/python2.7/ctypes/__init__.pyc'>
>>> import os
>>> print (os)
<module 'os' from '/Users/myuser/.pyenv/versions/2.7.15/lib/python2.7/os.pyc'>
>>> import django
>>> print (django)
<module 'django' from '/Users/myuser/git/myapp/env/lib/python2.7/site-packages/django/__init__.pyc'>
I couldn't find any result on google with the same issue.
What could be the issue?
The issue was caused by an old version of PIL that configured is configured in app.yaml. App Engine support out of the box up to version 1.1.17, which doesn't work with the latest python 2 version.
I installed version 5.0.0 of PIL and removed 1.1.17 from the App Engine settings and it solved the problem.

error on execute import django in python3 shell and script

when i want do an import django i get an error
ubuntu 18.04 with a reverse proxy (nginx) and uwsgi (mode emperor actived) in virtual env with python 3.6.3 and latest django 2.2.5
test.py:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")
import django
print("test")'
when i run python3 test.py i get :
(venv) :~/testproject/testproject/testproject$ python3.6 test.py
Traceback (most recent call last):
File "test.py", line 3, in <module>
from django.http import HttpResponse
File "/home/lukas/testproject/venv/lib/python3.6/site-packages/django/__init__.py", line 1, in <module>
from django.utils.version import get_version
File "/home/lukas/testproject/venv/lib/python3.6/site-packages/django/utils/version.py", line 4, in <module>
import subprocess
File "/usr/lib/python3.6/subprocess.py", line 140, in <module>
import threading
File "/usr/lib/python3.6/threading.py", line 7, in <module>
from traceback import format_exc as _format_exc
File "/usr/lib/python3.6/traceback.py", line 5, in <module>
import linecache
File "/home/lukas/testproject/venv/lib/python3.6/linecache.py", line 11, in <module>
import tokenize
File "/home/lukas/testproject/venv/lib/python3.6/tokenize.py", line 35, in <module>
from token import *
File "/home/lukas/testproject/testproject/testproject/token.py", line 1, in <module>
from django.contrib.auth.tokens import PasswordResetTokenGenerator
File "/home/lukas/testproject/venv/lib/python3.6/site-packages/django/contrib/auth/__init__.py", line 4, in <module>
from django.apps import apps as django_apps
File "/home/lukas/testproject/venv/lib/python3.6/site-packages/django/apps/__init__.py", line 2, in <module>
from .registry import apps
File "/home/lukas/testproject/venv/lib/python3.6/site-packages/django/apps/registry.py", line 426, in <module>
apps = Apps(installed_apps=None)
File "/home/lukas/testproject/venv/lib/python3.6/site-packages/django/apps/registry.py", line 46, in __init__
self.ready_event = threading.Event()
AttributeError: module 'threading' has no attribute 'Event'
i have the same error on python3 shell when i do import django whereas django have been installed with pip3 install and production mode is ok and developement mode with runserver is ok too.
can you help me, i m lost...
Do you have, by any chance, a token module in you django project?
As the python path is modified to prefer local modules rather than other pre-defined modules, the from token import * instruction will import from your module instead of the python lib one.
Try renaming your local modules to avoid collision with builtin python modules.

ImportError: cannot import name _remove_dead_weakref in django virtualenv

After upgrading my Ubuntu desktop to 18.04 from 16.04, the django's virtualenv refuses to start:
(.djangoenv) mw#desktop:~/theapp$ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
File "/home/mw/.djangoenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 10, in <module>
from django.apps import apps
File "/home/mw/.djangoenv/local/lib/python2.7/site-packages/django/apps/__init__.py", line 1, in <module>
from .config import AppConfig # NOQA
File "/home/mw/.djangoenv/local/lib/python2.7/site-packages/django/apps/config.py", line 4, in <module>
from django.core.exceptions import AppRegistryNotReady, ImproperlyConfigured
File "/home/mw/.djangoenv/local/lib/python2.7/site-packages/django/core/exceptions.py", line 5, in <module>
from django.utils.encoding import force_text
File "/home/mw/.djangoenv/local/lib/python2.7/site-packages/django/utils/encoding.py", line 10, in <module>
from django.utils.functional import Promise
File "/home/mw/.djangoenv/local/lib/python2.7/site-packages/django/utils/functional.py", line 1, in <module>
import copy
File "/usr/lib/python2.7/copy.py", line 52, in <module>
import weakref
File "/usr/lib/python2.7/weakref.py", line 14, in <module>
from _weakref import (
ImportError: cannot import name _remove_dead_weakref
On the djangoenv and outside it
$ python --version :
`Python 2.7.12`
Hoping to resolve the issue, I also install Python 2.7.16 on the desktop, so I get:
$ python2.7 --version
Python 2.7.16
Also when I try to install new virtualenv, I get the same error:
$ virtualenv .blaenv
Running virtualenv with interpreter /home/mw/.djangoenv/bin/python2
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/virtualenv.py", line 21, in <module>
import logging
File "/usr/lib/python2.7/logging/__init__.py", line 26, in <module>
import sys, os, time, cStringIO, traceback, warnings, weakref, collections
File "/usr/lib/python2.7/weakref.py", line 14, in <module>
from _weakref import (
ImportError: cannot import name _remove_dead_weakref
Answers to the same error in other contexts did not help and my search led to no more clues.
So really appreciate your hints.
As per https://askubuntu.com/questions/981663/python2-7-broken-by-weakref-import-error-please-help you probably need to recreate your virtualenv. I suspect your problem here is that you need to deactivate your current env before you try to make the new one, in order to ensure that your system python2 interpreter is the one running the virtualenv command.

pip error on running pip freeze

I made a registration system with Django using celery, redis. It was working fine till today. But getting this error 'Redis is not install' when try to register a new user. I was trying to check packages installed using pip and getting this.
Traceback (most recent call last):
File "/home/chhuti/projects/venv/chhuti/bin/pip", line 7, in <module>
from pip import main
File "/home/chhuti/projects/venv/chhuti/lib/python3.6/site-
packages/pip/__init__.py", line 26, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/home/chhuti/projects/venv/chhuti/lib/python3.6/site-
packages/pip/utils/__init__.py", line 23, in <module>
from pip.locations import (
File "/home/chhuti/projects/venv/chhuti/lib/python3.6/site-
packages/pip/locations.py", line 9, in <module>
from distutils import sysconfig
File
"/home/chhuti/projects/venv/chhuti/lib/python3.6/distutils/__init__.py", line 25, in <module>
from distutils import dist, sysconfig
ImportError: cannot import name 'dist'
I am using
pip version 9.0.2,
Python version 3.6.3
Django 1.11
Have been stuck here for a long time now, couldn't solve it.

no module name datetime after ubuntu 13.04 upgrade

Just did an upgrade from ubuntu 12.10 to 13.04 and getting this when running django site in virtualenv
(virtualenv)sysadmin#ubuntu:~/webapps/devsite/djangosite$ ./manage.py runserver
Traceback (most recent call last):
File "./manage.py", line 2, in <module>
from django.core.management import execute_manager
File "/home/sysadmin/webapps/devsite/virtualenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 7, in <module>
from django.core.management.base import BaseCommand, CommandError, handle_default_options
File "/home/sysadmin/webapps/devsite/virtualenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 14, in <module>
from django.utils.encoding import smart_str
File "/home/sysadmin/webapps/devsite/virtualenv/local/lib/python2.7/site-packages/django/utils/encoding.py", line 4, in <module>
import datetime
ImportError: No module named datetime
Just do
virtualenv /home/sysadmin/webapps/devsite/virtualenv/
this will reinstall Python in the VirtualEnv and it will work after that (and you won't need to reinstall the libraries).
Update: when I was dealing with the same problem after upgrading from 14.04 to 14.10, virtualenv didn't want to overwrite the existing symlink to Python, so I had to remove it first (in this example that would be rm /home/sysadmin/webapps/devsite/virtualenv/python)