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)
Related
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.
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.
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.
My sklearn works well before, after installing and updating a couple of other packages, I cannot import any model from sklearn.
The versions:
Python 2.7.12
Anaconda 2.4.1 (x86_64)
sklearn: 0.17.1 (downgrade from 0.18)
spicy: 0.18.1
Measures I've tried:
restart the shell---> same error
uninstall sklearn, and reinstall it (the newest version is 0.18), downgrade it to 0.17--> same error
install sklearn and keep the version 0.18 -->still error
My code:
from sklearn import svm
The error
Traceback (most recent call last):
File "<ipython-input-1-fe795c4388c4>", line 3, in <module>
from sklearn import svm
File "//anaconda/lib/python2.7/site-packages/sklearn/svm/__init__.py", line 13, in <module>
from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC, \
File "//anaconda/lib/python2.7/site-packages/sklearn/svm/classes.py", line 4, in <module>
from .base import _fit_liblinear, BaseSVC, BaseLibSVM
File "//anaconda/lib/python2.7/site-packages/sklearn/svm/base.py", line 11, in <module>
from ..preprocessing import LabelEncoder
File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/__init__.py", line 8, in <module>
from .data import Binarizer
File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/data.py", line 25, in <module>
from ..utils.sparsefuncs import (inplace_column_scale,
ImportError: cannot import name inplace_column_scale
Besides svm, when I import tree, linear_model, the same thing happens.
from sklearn.models import linear_model
The error:
Traceback (most recent call last):
File "<ipython-input-3-540f6792b379>", line 1, in <module>
from sklearn.models import linear_model
ImportError: No module named models
Code:
from sklearn import tree
error:
Traceback (most recent call last):
File "<ipython-input-4-fcc6e7d2ee3e>", line 1, in <module>
from sklearn import tree
File "//anaconda/lib/python2.7/site-packages/sklearn/tree/__init__.py", line 6, in <module>
from .tree import DecisionTreeClassifier
File "//anaconda/lib/python2.7/site-packages/sklearn/tree/tree.py", line 30, in <module>
from ..feature_selection.from_model import _LearntSelectorMixin
File "//anaconda/lib/python2.7/site-packages/sklearn/feature_selection/__init__.py", line 7, in <module>
from .univariate_selection import chi2
File "//anaconda/lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.py", line 15, in <module>
from ..preprocessing import LabelBinarizer
File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/__init__.py", line 8, in <module>
from .data import Binarizer
File "//anaconda/lib/python2.7/site-packages/sklearn/preprocessing/data.py", line 25, in <module>
from ..utils.sparsefuncs import (inplace_column_scale,
ImportError: cannot import name inplace_column_scale
To solve the error:
ImportError: cannot import name 'OrdinalEnconder' from 'sklearn.preprocessing'
(C:\ProgramData\Anaconda3\lib\site-packages\sklearn\preprocessing\__init__.py)
You need to go path "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\preprocessing" and check the name of OneLabelEncoder in python file __init__.py . The name may be LabelEncoder or a different name. You need import the module with same name.
The following screenshot should help you understand this better:
Try this within your terminal:
conda install -c anaconda scikit-learn=0.18.1
If it does not work go to your terminal and try:
conda update anaconda
After the update is complete, then try the first bit of code again
Hopefully it works
please see this question.
ImportError: cannot import name inplace_column_scale.
I think you face the same problem. There are several ways to solve it.
For windows. delete python27\Lib\site-packages\sklearn\utils\sparsefuncs.pyd.
For mac and linux, delete /usr/local/lib/python2.7/site-packages/sklearn/utils/sparsefuncs.so.
If you use anaconda, delete anaconda/lib/python2.7/site-packages/sklearn/utils/sparsefuncs.so
reinstall the sklearn.
pip uninstall scikit-learn
pip install scikit-learn
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.