I'm trying to get a work project that I git-cloned from work (used in numerous other places, I know the project works fine) to run on my MacBook. I installed Django (via sudo python setup.py install), as well as MySQL, the Python MySQL wrapper, and also virtualenv with virtualenvwrapper.
After creating a virtualenv for my project (virtualenv is created fine), and doing a pip install for the project requirements (all of which install into the proper virtualenv directory), an attempt to do a runserver command spits out the following:
Traceback (most recent call last):
File "manage.py", line 12, in <module>
execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 436, in execute_manager
setup_environ(settings_mod)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 419, in setup_environ
project_module = import_module(project_name)
File "/Library/Python/2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named website-backend
First try to import this library from python or ./manage.py shell.
If that fails import sys and check if your lib is in sys path print sys.path
Related
I can't run pip2, which is installed from its Arch Linux package:
$ pip2
Traceback (most recent call last):
File "/usr/bin/pip2", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 47, in <module>
from pkg_resources.extern.six.moves import urllib, map, filter
ImportError: No module named moves
I reinstalled python2-pip2 and python2-setuptools with no results. This has been a problem for months.
While I don't understand the issue, it is possible to reset it by removing locally (--user) installed packages:
Move all packages installed as the user:
mv ~/.local/lib/python2.7/site-packages ~/site-packages-bak
or try to pinpoint the problematic files. In my case, for some reason I had a python file and its pyc file lying around the site-packages directory and just moving them solved my issue:
mv ~/.local/lib/python2.7/site-packages/six.py ~/six.py-bak
mv ~/.local/lib/python2.7/site-packages/six.pyc ~/six.pyc-bak
I am running python based software that requires a virtualenv with various additional python packages installed therein. Here are the install instructions:
Clone the repository to a shared filesysem on a cluster
>git clone https://github.com/jgurtowski/nanocorr
>cd nanocorr
Create a virtual environment to install python dependencies
>virtualenv nanocorr_ve
>source nanocorr_ve/bin/activate
install the following packages using pip:
pip install git+https://github.com/cython/cython
pip install numpy
pip install h5py
pip install git+https://github.com/jgurtowski/pbcore_python
pip install git+https://github.com/jgurtowski/pbdagcon_python
pip install git+https://github.com/jgurtowski/jbio
pip install git+https://github.com/jgurtowski/jptools
#Finally install the nanocorr package itself
> python setup.py install
I achieved this with no problems. However, While running the software, I found that it was failing with the following traceback.
(nanocorr_ve)[nanocorr_test]$ correctOxford
Traceback (most recent call last):
File "/local/workdir/malonge/nanocorr_test/nanocorr/nanocorr_ve/bin/correctOxford", line 9, in <module>
load_entry_point('jptools==0.1', 'console_scripts', 'correctOxford')()
File "/local/workdir/malonge/nanocorr_test/nanocorr/nanocorr_ve/lib/python2.7/site- packages/pkg_resources/__init__.py", line 558, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/local/workdir/malonge/nanocorr_test/nanocorr/nanocorr_ve/lib/python2.7/site- packages/pkg_resources/__init__.py", line 2682, in load_entry_point
return ep.load()
File "/local/workdir/malonge/nanocorr_test/nanocorr/nanocorr_ve/lib/python2.7/site- packages/pkg_resources/__init__.py", line 2355, in load
return self.resolve()
File "/local/workdir/malonge/nanocorr_test/nanocorr/nanocorr_ve/lib/python2.7/site- packages/pkg_resources/__init__.py", line 2361, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/local/workdir/malonge/nanocorr_test/nanocorr/nanocorr_ve/lib/python2.7/site- packages/jptools/correct.py", line 21, in <module>
from pbtools.pbdagcon.q_sense import output_dag_info
File "/local/workdir/malonge/nanocorr_test/nanocorr/nanocorr_ve/lib/python2.7/site- packages/pbtools/pbdagcon/q_sense.py", line 50, in <module>
from pbcore.io import FastaReader
File "/programs/python/lib/python2.7/site-packages/pbcore-1.0.0- py2.7.egg/pbcore/io/__init__.py", line 31, in <module>
from .BasH5IO import *
File "/programs/python/lib/python2.7/site-packages/pbcore-1.0.0- py2.7.egg/pbcore/io/BasH5IO.py", line 37, in <module>
import h5py, numpy as np, os.path as op
File "/programs/python/lib/python2.7/site-packages/h5py-2.5.0-py2.7-linux- x86_64.egg/h5py/__init__.py", line 13, in <module>
from . import _errors
ImportError: /programs/python/lib/python2.7/site-packages/h5py-2.5.0-py2.7-linux-x86_64.egg/h5py/_errors.so: undefined symbol: PyUnicodeUCS2_DecodeUTF8
I have found details as to the specific error itself, but I think the source of the problem is that the traceback clearly shows a transition from modules being imported from the /local virtualenv site-packages to another site-packages directory in /programs.
My question is the following: Given that I have the same python packages installed in two separate places, 1 in the system wide location and one in virtualenv, how do I ensure that other programs properly import all modules from within the same virtualenv sit-packages directory. I thought this would have been done automatically. I am not 100% sure that this is the sole reason for the error, but being able to fix this would help me to further debug.
It depends on how you set up your env. virtualenv has a flag option that forces it to not use the system site packages
virtualenv --no-site-packages my_env
It is the default behavior for recent versions (>=1.7).
If you've defined a PYTHONPATH environment variable, that will affect your virtualenv environment as well.
I'm trying to use the virtualenvwrapper to make a python 3 based virtualenv. However,I'm when I pass the optional interpreter argument, I'm seeing this error. I'm running Ubuntu 15.04. I tried reinstalling virtualenv and virtualenvwrapper without success. Thanks for all your help!
$ mkvirtualenv scriptcutter --python=/usr/bin/python3
Running virtualenv with interpreter /usr/bin/python3
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
if not enabled():
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Original exception was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
I come across same issue, but after I downgrade virtualenv to 12.0.2, this problem disappears.
This is sort of a workaround for now.
Create a virtualenv using pyvenv.
# install pyvenv on Ubuntu
sudo apt-get install python3-venv
To minimize disruption in your normal workflow, pass a destination directory that is the same as the one used by virtualenvwrapper Like so,
pyvenv example ~/.virtualenvs/example
This is automatically working with workon and cdproject commands. I don't use much else that is provided by virtualenvwrapper
Hope this helps.
You can upgrade to the most recent version of virtualenv, with:
sudo pip install --upgrade https://github.com/pypa/virtualenv/archive/master.zip
virtualenv --version
# Returns 15.2.0.dev0 when I ran it
The following command then works:
mkvirtualenv scriptcutter --python=/usr/bin/python3
Apparently, the develop branch was dropped, so the URL with "develop" will no longer work. My answer was based off of #pjotr_dolphin's comment, with the URL updated.
I have installed Django 1.6.5 with PIP and Python 2.7.8 from the website.
I ran django-admin.py startproject test123, switched to test123 directory, and ran the command python manage.py runserver, then i get this:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/conf/__init__.py", line 50, in _setup
self._configure_logging()
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/conf/__init__.py", line 72, in _configure_logging
from django.utils.log import DEFAULT_LOGGING
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/utils/log.py", line 7, in <module>
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/views/debug.py", line 10, in <module>
from django.http import (HttpResponse, HttpResponseServerError,
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/http/__init__.py", line 2, in <module>
from django.http.request import (HttpRequest, QueryDict, UnreadablePostError,
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/http/request.py", line 11, in <module>
from django.core import signing
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/signing.py", line 45, in <module>
from django.utils.crypto import constant_time_compare, salted_hmac
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/utils/crypto.py", line 6, in <module>
import hmac
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py", line 8, in <module>
from operator import _compare_digest as compare_digest
ImportError: cannot import name _compare_digest
Found out that operator is a standard python library. Why cant it not import it?
P.S. I did try it in the command line, I can import the operator module, but I get an error on this statement: from operator import _compare_digest as compare_digest
Followed this SO answer:
Uninstall python.org version of python2.7 in favor of default OS X python2.7
Then changed my .bash_profile Python path to /usr/lib/python for the default OSX python path.
Uninstalled Django and MySQL-Python:
sudo pip uninstall django
sudo pip uninstall MySQL-Python
And then again reinstalled everything, but with MySQL-Python being the first and second Django.
After these steps, everything is working.
I get this error with anaconda as my default python and django1.7 while trying to use startproject.
I deleted the venv and recreated it with
virtualenv -p /usr/bin/python2.7 venv
startproject was working again.
You most likely have another file named operator.py on your PYTHONPATH (probably in the current working directory), which shadows the standard library operator module..
Remove or rename the file.
For those not wanting to switch to Apple's python, simply deleting the virtualenv and rebuilding it worked fine for me.
Tip: Don't forget to pip freeze > requirements.txt first if you aren't already tracking your package requirements. That way you can pip install -r requirements.txt to get up and running again quickly.
I am trying to install Django-1.5.5 on windows 7. I have installed it but when I try to punch in "django-admin.py startproject mysite" I get following error:
C:\Users\DIPANSHU>django-admin.py startproject mysite
Traceback (most recent call last):
File "C:\Django-1.5.5\django\bin\django-admin.py", line 2, in <module>
from django.core import management
File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
9, in <module>
from django.core.management.base import BaseCommand, CommandError, han
fault_options
File "C:\Python27\lib\site-packages\django\core\management\base.py", lin
in <module>
from django.utils.encoding import force_str
File "C:\Python27\lib\site-packages\django\utils\encoding.py", line 10,
dule>
from urllib import quote
File "C:\Python27\lib\urllib.py", line 26, in <module>
import socket
File "C:\Python27\lib\socket.py", line 47, in <module>
import _socket
ImportError: DLL load failed: The specified procedure could not be found.
Previously, I tried with Django-1.4.2 but problem was same. I am having Python27.Please assist.
Yups! Finally got it! So here's what I did:
Removed python completely and installed it again.
adjust my PATH environment variable to include paths to the Python executable & additional scripts.
Installed Setuptools
Installed pip using easy_install pip.
Installed Django using pip install django.
Note: If your Python is installed in C:\Python27\, the following paths need to be added to PATH: C:\Python27\;C:\Python27\Scripts;
Reference: https://docs.djangoproject.com/en/dev/howto/windows/
Thanks a lot for your valuable inputs and bearing with me! :-)
I would make sure that DJango is installed by running
python -c "import django; print(django.get_version())"
https://docs.djangoproject.com/en/1.6/intro/tutorial01/
I found the Django tutorial on their site to be very good
Also what exactly are you typing into the command prompt ? You should simply be in directory C:\Users\DIPANSHU> in the command shell
EDIT: you should be in the directory where you installed Django