Error installing Django - python

Error Traceback below.
import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django

If you're installing django on a system level, then try installing via root like this
sudo pip install django
If you're in a virtualenv, then the a simple pip install django would also work.
To know what a virtualenv is, please refer: https://virtualenv.readthedocs.org/en/latest/

I see The read operation timed out - maybe there is problem with server or too many people try to use server at this time. Try to install tomorrow.
If you can download django on local disk as whl file then you can use
pip install downloaded-django-package.whl
btw: it can be problem with pip so you can also try to upgrade pip
pip install --upgrade pip
EDIT:
If you get error with Permission denied then you have to use sudo as #ishaar suggests.

Related

Python SAML authentication

I'm trying to build a SAML authentication mechanism in Python using the OneLogin module, but I can't even get started. Trying from the example code provided in the docs, I can't even load the package.
This works:
import onelogin
but this gets a ModuleNotFoundError:
>>> from onelogin.saml2.auth import OneLogin_Saml2_Auth
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'onelogin.saml2'
I only managed to get this working on a Linux machine, so hope you're not on windows. Here's what worked for me.
I had to do a seperate install of hte xmlsec-library first:
apt-get install xmlsec1 openssl python-lxml libxmlsec1 libxmlsec1-dev
and then I was able to
pip install python3-saml
and there were no complains anymore.
You need to install Xmlsec first and then python3-saml but if you are on Windows, Xmlsec has some issues but as with python 3.6 and below the problem is solved. Use this link to download the wheel file for your python version https://github.com/mehcode/python-xmlsec/releases
Install the wheel file using
pip install <wheel_file_name>
As with Python 3.7, the only way out is to install xmlsec on a Linux machine as it is not yet supported on Windows.

Unable to continue Wagtail installation, "./migrate.py migrate" traceback

I'm installing Wagtail on Linode Ubuntu 16.04 LTS. I followed the following guides so far:
https://www.linode.com/docs/getting-started
http://docs.wagtail.io/en/v1.9/getting_started/index.html
For the second link, I followed the installation guides for Python, pip, virtualenv and the required Pillow libs.
I got up to the following in the installation process:
$ pip install -r requirements.txt
$ ./manage.py migrate
The migrate command produces the following error:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
I haven't been able to find a solution for this. I am doing all of this in venv. Any help is greatly appreciated.
That error suggests that Django hasn't been installed.
What is the output of pip install -r requirements.txt?
I solved the issue by re-doing everything. Created new virtualenv, activated, and continued from there. Everything seems to be working correctly so far. Thanks!

"InvalidRequirement: Invalid requirement, parse error" error after updating a python package

After updating a package (IPython in my case) using pip install -U ipython running any Python script that uses entry points fails with this error:
Traceback (most recent call last):
File "/home/adrian/dev/indico/env/bin/indico", line 5, in <module>
from pkg_resources import load_entry_point
...
File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 94, in __init__
requirement_string[e.loc:e.loc + 8], requirement_string))
pkg_resources._vendor.packaging.requirements.InvalidRequirement: Invalid requirement, parse error at "'< 2.0'"
Nothing else changed, I did not update any other libraries.
This is caused by an issue in setuptools==20.2.1 which is pulled in by IPython (setuptools>..), so a pip install -U updated it.
Until a fixed version is released or the broken version is pulled from PyPI there is a simple workaround (but note that it will break again if something updates setuptools):
pip install -U pip
pip uninstall setuptools
pip install 'setuptools<20.2'
The pip update is needed since older versions of pip will not work without setuptools being installed
See these IRC logs and BitBucket issue for details:
http://chat-logs.dcpython.org/day/pypa/2016-02-25
https://bitbucket.org/pypa/setuptools/issues/502/packaging-164-does-not-allow-whitepace
Try downgrading your pip to 8.1.1:
pip install pip==8.1.1
That solved it for me.
In my case I had package = "2.8.0" in my Pipfile. Changing it to package = "==2.8.0" fixed this error for me.

Redhat trying to use pip ImportError: No module named pip

I am trying to use pip on my Redhat system.
I installed pip following the instructions here, but when I try to use it, for example pip install, I get the following error code:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in ?
from pip import main
ImportError: No module named pip
this issue due to common user do not have privilege to access packages py file.
1. root user can run 'pip list'
2. other common user cannot run 'pip list'
[~]$ pip list
Traceback (most recent call last):
File "/usr/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named pip._internal
solution :
root user login and run
chmod -R 755 /usr/lib/python2.7
fix this issue.
If pip is already installed and your unable to access it, one of the reason could be that you don't have permissions to read or execute the library. Try doing
sudo chmod -R u+rx /usr/lib/python2.7/site-packages/pip/
If pip is installed in a different folder, you can obtain the folder path by doing
>>> import pip
>>> pip.__path__
['/usr/lib/python2.7/site-packages/pip']
If you don't have root rights and running on python 2.6 then you can try this file https://bootstrap.pypa.io/2.6/get-pip.py (it is from same instruction you used, it is a simple python script which installs all dependencies and pip itself) and run it with command python get-pip.py --user

debugging python setup.py for an open source library - bcfg2

When I install bcfg2 - http://bcfg2.org using
pip install git+git://git.mcs.anl.gov/bcfg2.git#egg=Bcfg2
or
pip install bcfg2
I am able to get bcfg2 working. Calling sudo bcfg2-admin init, shows me the set-up configuration steps/stdin prompt as expected.
When I introduce the -e option like this (in a new/clean virtualenv),
pip install -e git+git://git.mcs.anl.gov/bcfg2.git#egg=Bcfg2
And I attempt to call sudo bcfg2-admin init, I get an error message:-
calvin$ bcfg2-admin init
Traceback (most recent call last):
File "/Users/calvin/.virtualenvs/bcfg2/bin/bcfg2-admin", line 7, in <module>
execfile(__file__)
File "/Users/calvin/.virtualenvs/bcfg2/src/bcfg2/src/sbin/bcfg2-admin", line 6, in <module>
import Bcfg2.Server.Core
ImportError: No module named Bcfg2.Server.Core
This leads me to think that there is something wrong with the way setup.py is written for bcfg2. The file is located here - https://github.com/Bcfg2/bcfg2/blob/master/setup.py
Appreciate any input from pythonistas who are experts with python packaging and the configuration of setup.py.
You've installed to a virtual environment (-e). However when you run this with sudo python gets executed as root without the virtual environment available.
If you run sudo su you should be dropped into a root shell. You can then activate the virtual environment and run bcfg2-admin.
The setup.py has a bug.
Figured it out, fixed it and sent a pull request to bcfg2 maintainers.
Reference - https://github.com/Bcfg2/bcfg2/pull/28

Categories

Resources