Installing Django and Python Suds (without admin rights) - python

I am trying to setup my project environment which uses the following:
Python 2.5.2
Django 1.3
Python Suds
The server I am running it on already has Python (2.5.2) and Django (1.1) installed but I want to use a newer version of Django and dont have administrator rights to upgrade. How do I go about installing this again?
Should I have to install Python + Django + Suds in a seperate directory? How would I replace standard python paths to this new one?
Thanks!

You can use virtual_env, I have used to play with another (unrelated) python framework buildbot

I would install it Django + Suds in a new directory! then you can grant access to everyone in this dir! then If you are running apache you just have to add this new folder to PYTHONPATH!
Just for record, I have never tried that, but it should work!
try searching about PYTHONPATH in google too, here is one link that might help:
http://www.stereoplex.com/blog/understanding-imports-and-pythonpath
cheers

A Complete Guide To setup django in other path
Installing django through pip
Well many use pip package manager for their install purpose (not my favorite).
to install django through pip you do something like:
pip install django
it will install django in a path which is not accessible by non-root users.
So you must first add the installation place for it.
pip install django --install-option="--prefix=$SOME_PLACE_WE_HAVE_ACCESS_TO" django
This $SOME_PLACE_WE_HAVE_ACCESS_TO can be /home/user/ directory.
now login to python and do the import:
import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
What are we doing wrong????
PYTHONPATH
well as long as you have not installed django in PYTHONPATH python doesn't know where to import the module!!!
do this two steps:
BASH:
echo $PYTHONPATH
PYTHON:
import sys
print sys.path
well sys.path show the path of packages locations installed in python.
and $PYTHONPATH is empty...
The only thing you have to do is to add the path of django egg file to PYTHONPATH
for example in mine its:
/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg
to add it to PYTHONPATH do this:
BASH:
export PYTHONPATH={{EGG PATH}}
which {{EGG PATH}} is the location of your django egg.
WHAT ABOUT django-admin?
well you have to run it from the place that django has set it up in somewhere it has been installed called bin
for that you can add the path of that bin (Think it might be ~/bin or any_place_you_installed/bin) to $PATH...
just like PYTHONPATH we do:
export PATH=$PATH:~/bin
ATTENTION >> : after $PATH is essential!!! to know why do a: echo $PATH
ATTENTION >> ~/bin must be django bin directory so pay attention to that.
Installing django through source
OH My god That's my favorite.
there is nothing difference with the thing up there just insted pip use setup.py...
for that you must have setuptools installed... (I think pip will install that itself if pip raises error for setuptools you must do the whole thing I told up there for django for setuptools too.)
after you installed setuptools you must do this:
./setup.py install --prefix=$PATH_YOU_DESIRE
the rest is the same...
REFERENCES
1 : Installing package through pip in other location.
2 : How to add a PATH To $PATH.

Related

when ever i am trying to start a project after i have installed django, execution displays No Module Found Error :django module or django.core

(.env) C:\Users\shara\Desktop\testfolder\_djhole>pip install Django (executed)
(.env) C:\Users\shara\Desktop\testfolder\_djhole>django-admin start project my site (No Module Found Error)
I have repeated this process for a long time. Cannot start working on Django so far due to this:
ModuleNotFoundError: No module named 'django.core'; 'Django' is not a package
I have uninstalled it and reinstalled it several times. when I use pip freeze then
asgiref==3.2.7
Django==3.0.7
pytz==2020.1
sqlparse==0.3.1
But still cannot start working on Django because the module is not found an error.
By the way, there is only one python version 3.8.3 and added to the path. I hope that there would be some genius out there who could give me some answer because I have searched all over the internet for resolving this diabolical problem and got no company.
If you do not have such an environment for your current project, then you need to do this
mkvirtualenv .env
You either already have an environment or just created it. Then you need to use the virtual environment. You can do that with this:
workon .env
Check if there is a requirements.txt file in the root of your project. If there is, then it means someone (perhaps you), has created a file which lists all of the packages that have to be installed to get it up and running. If that’s the case, then you only need to run this:
pip install -R requirements.txt
If you don’t have a requirements.txt files, then just run this:
pip install django
This will install the latest version of Django. If you need a specific version, then you can do that as well with:
pip install django==2.2.4

Django-admin creates wrong django version inside virtualenv

I've created a n new directory, a virtualenv and installed a django-toolbelt inside it. The django-version should be 1.8 but when I call 'django-admin.py version' it says 1.6. So when I start a new project it creates a 1.6. I thought virtualenv was supposed to prevent this. What am I doing wrong?
Edit: I think it has to do with the PATH (?). Like it's calling the wrong django-admin version. I'm on Windows 7. Still don't know how to fix it.
I came across this problem too. In the official document, I found that, in a virtual environment, if you use the command 'django-admin', it would search from PATH usually in '/usr/local/bin'(Linux) to find 'django-admin.py' which is a symlink to another version of django. This is the reason of what happened finally.
So there are two methods to solve this problem:
re-symlink your current version django-admin(site-packages/django/bin/django-admin.py) to 'usr/local/bin/django-admin' or 'usr/local/bin/django-admin.py'
REMIND: This is a kind of global way so that it will effects your other django projects, so I recommend the second method
cd to your_virtual_env/lib/python3.x/site-packages/django/bin/(of course you should activate your virtual environment), and then use 'python django-admin.py startproject project_name project_full_path' to create django project
Try and install Django into the virtual environment as well:
pip install django
It should install the latest version, you can also specify a particular version (let's say 1.8.2) if you need to:
pip install django==1.8.2
Either way you'll have the correct version of Django in your virtual environment and it should work as you expect then.
You can also use the following command to see what version you have installed:
pip show django
Update:
It seems that you have the correct version installed in your virtual environment, but for some reason your Windows 7 use the system Django installation instead while you use manage.py or django-admin.py directly. However, you can use python manage.py or python django-admin.py instead, which seems to work as expected (and use the virtualenv Django installation).
I had the same problem. Could be related to your zsh/bash settings.
I realized that using zsh (my default) I would get django-admin version 1.11 despite the Django version was 2.1! When I tried the same thing with bash I would get django-admin version 2.1 (the correct version). Certainly a misconfiguration.
So, I strongly suggest you check your zsh or bash settings to check for paths you might have.
Create a virtual environment for a project:
$ mkdir cd my_project_folder
$ cd my_project_folder
$ virtualenv venv
$ source venv/bin/activate
And now install django
(venv) ~$ pip install django==1.8
manage.py runserver in virtualenv using wrong django version
pip / virtualenv / django installation issue

Django installed in dist-packages

I am working on an Amazon Linux AMI (version 2013.09).
My goal, among other things, is to have Django up and running.
So here's what I do:
Install pip using yum (it installs pip 7.0.3 in Python2.7/dist-packages)
Install virtualenv using pip
Create a virtualenv (with --no-site-packages)
Install Django using pip inside the virtualenv (this installs Django in the virtenv's Python directory, inside dist-packages)
This seems fine, until I try to use manage.py. The following line:
python manage.py collectstatic --noinput -c -l > /dev/null
Invokes the following error:
OSError: [Errno 2] No such file or directory: '...my-env/lib/python2.7/site-packages/django/contrib/admin/static'
Which is true, because the entire Django infrastructure is in dist-packages, not site-packages.
What is the correct way of fixing this dependency?
Thanks!
UPDATE 28.06.15
The reason Django attempts to access site-packages is the 'STATIC_ROOT' definition in its settings.py file.
Thing is, I installed Django in the exact same way, using the same settings, a couple of years ago, and it worked perfectly.
So what's changed? Why has pip suddenly moved to dist-packages?
sometimes PYTHON_INSTALL_LAYOUT="amzn" gets set in a shell and then stuff annoyingly goes into dist-packages.
To disable this annoyance,
unset PYTHON_INSTALL_LAYOUT

Unable to import a module that is definitely installed

After installing mechanize, I don't seem to be able to import it.
I have tried installing from pip, easy_install, and via python setup.py install from this repo: https://github.com/abielr/mechanize. All of this to no avail, as each time I enter my Python interactive I get:
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mechanize
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mechanize
>>>
The installations I ran previously reported that they had completed successfully, so I expect the import to work. What could be causing this error?
In my case, it is permission problem. The package was somehow installed with root rw permission only, other user just cannot rw to it!
I had the same problem: script with import colorama was throwing an ImportError, but sudo pip install colorama was telling me "package already installed".
My fix: run pip without sudo: pip install colorama. Then pip agreed it needed to be installed, installed it, and my script ran. Or even better, use python -m pip install <package>. The benefit of this is, since you are executing the specific version of python that you want the package in, pip will unequivocally install the package into the "right" python. Again, don't use sudo in this case... then you get the package in the right place, but possibly with (unwanted) root permissions.
My environment is Ubuntu 14.04 32-bit; I think I saw this before and after I activated my virtualenv.
I was able to correct this issue with a combined approach. First, I followed Chris' advice, opened a command line and typed 'pip show packagename'
This provided the location of the installed package.
Next, I opened python and typed 'import sys', then 'sys.path' to show where my python searches for any packages I import. Alas, the location shown in the first step was NOT in the list.
Final step, I typed 'sys.path.append('package_location_seen_in_step_1'). You optionally can repeat step two to see the location is now in the list.
Test step, try to import the package again... it works.
The downside? It is temporary, and you need to add it to the list each time.
It's the python path problem.
In my case, I have python installed in:
/Library/Frameworks/Python.framework/Versions/2.6/bin/python,
and there is no site-packages directory within the python2.6.
The package(SOAPpy) I installed by pip is located
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
And site-package is not in the python path, all I did is add site-packages to PYTHONPATH permanently.
Open up Terminal
Type open .bash_profile
In the text file that pops up, add this line at the end:
export PYTHONPATH=$PYTHONPATH:/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
Save the file, restart the Terminal, and you're done
The Python import mechanism works, really, so, either:
Your PYTHONPATH is wrong,
Your library is not installed where you think it is
You have another library with the same name masking this one
I have been banging my head against my monitor on this until a young-hip intern told me the secret is to "python setup.py install" inside the module directory.
For some reason, running the setup from there makes it just work.
To be clear, if your module's name is "foo":
[burnc7 (2016-06-21 15:28:49) git]# ls -l
total 1
drwxr-xr-x 7 root root 118 Jun 21 15:22 foo
[burnc7 (2016-06-21 15:28:51) git]# cd foo
[burnc7 (2016-06-21 15:28:53) foo]# ls -l
total 2
drwxr-xr-x 2 root root 93 Jun 21 15:23 foo
-rw-r--r-- 1 root root 416 May 31 12:26 setup.py
[burnc7 (2016-06-21 15:28:54) foo]# python setup.py install
<--snip-->
If you try to run setup.py from any other directory by calling out its path, you end up with a borked install.
DOES NOT WORK:
python /root/foo/setup.py install
DOES WORK:
cd /root/foo
python setup.py install
I encountered this while trying to use keyring which I installed via sudo pip install keyring. As mentioned in the other answers, it's a permissions issue in my case.
What worked for me:
Uninstalled keyring:
sudo pip uninstall keyring
I used sudo's -H option and reinstalled keyring:
sudo -H pip install keyring
In PyCharm, I fixed this issue by changing the project interpreter path.
File -> Settings -> Project -> Project Interpreter
File -> Invalidate Caches… may be required afterwards.
I couldn't get my PYTHONPATH to work properly. I realized adding export fixed the issue:
(did work)
export PYTHONPATH=$PYTHONPATH:~/test/site-packages
vs.
(did not work)
PYTHONPATH=$PYTHONPATH:~/test/site-packages
This problem can also occur with a relocated virtual environment (venv).
I had a project with a venv set up inside the root directory. Later I created a new user and decided to move the project to this user. Instead of moving only the source files and installing the dependencies freshly, I moved the entire project along with the venv folder to the new user.
After that, the dependencies that I installed were getting added to the global site-packages folder instead of the one inside the venv, so the code running inside this env was not able to access those dependencies.
To solve this problem, just remove the venv folder and recreate it again, like so:
$ deactivate
$ rm -rf venv
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
Something that worked for me was:
python -m pip install -user {package name}
The command does not require sudo. This was tested on OSX Mojave.
In my case I had run pip install Django==1.11 and it would not import from the python interpreter.
Browsing through pip's commands I found pip show which looked like this:
> pip show Django
Name: Django
Version: 1.11
...
Location: /usr/lib/python3.4/site-packages
...
Notice the location says '3.4'. I found that the python-command was linked to python2.7
/usr/bin> ls -l python
lrwxrwxrwx 1 root root 9 Mar 14 15:48 python -> python2.7
Right next to that I found a link called python3 so I used that. You could also change the link to python3.4. That would fix it, too.
In my case it was a problem with a missing init.py file in the module, that I wanted to import in a Python 2.7 environment.
Python 3.3+ has Implicit Namespace Packages that allow it to create a packages without an init.py file.
Had this problem too.. the package was installed on Python 3.8.0 but VS Code was running my script using an older version (3.4)
fix in terminal:
py .py
Make sure you're installing the package on the right Python Version
I had colorama installed via pip and I was getting "ImportError: No module named colorama"
So I searched with "find", found the absolute path and added it in the script like this:
import sys
sys.path.append("/usr/local/lib/python3.8/dist-packages/")
import colorama
And it worked.
I had just the same problem, and updating setuptools helped:
python3 -m pip install --upgrade pip setuptools wheel
After that, reinstall the package, and it should work fine :)
The thing is, the package is built incorrectly if setuptools is old.
If the other answers mentioned do not work for you, try deleting your pip cache and reinstalling the package. My machine runs Ubuntu14.04 and it was located under ~/.cache/pip. Deleting this folder did the trick for me.
Also, make sure that you do not confuse pip3 with pip. What I found was that package installed with pip was not working with python3 and vice-versa.
I had similar problem (on Windows) and the root cause in my case was ANTIVIRUS software! It has "Auto-Containment" feature, that wraps running process with some kind of a virtual machine.
Symptoms are: pip install somemodule works fine in one cmd-line window and import somemodule fails when executed from another process with the error
ModuleNotFoundError: No module named 'somemodule'
In my case (an Ubuntu 20.04 VM on WIN10 Host), I have a disordered situation with many version of Python installed and variuos point of Shared Library (installed with pip in many points of the File System). I'm referring to 3.8.10 Python version.
After many tests, I've found a suggestion searching with google (but' I'm sorry, I haven't the link). This is what I've done to resolve the problem :
From shell session on Ubuntu 20.04 VM, (inside the Home, in my case /home/hduser), I've started a Jupyter Notebook session with the command "jupyter notebook".
Then, when jupyter was running I've opened a .ipynb file to give commands.
First : pip list --> give me the list of packages installed, and, sympy
wasn't present (although I had installed it with "sudo pip install sympy"
command.
Last with the command !pip3 install sympy (inside jupyter notebook
session) I've solved the problem, here the screen-shot :
Now, with !pip list the package "sympy" is present, and working :
In my case, I assumed a package was installed because it showed up in the output of pip freeze. However, just the site-packages/*.dist-info folder is enough for pip to list it as installed despite missing the actual package contents (perhaps from an accidental deletion). This happens even when all the path settings are correct, and if you try pip install <pkg> it will say "requirement already satisfied".
The solution is to manually remove the dist-info folder so that pip realizes the package contents are missing. Then, doing a fresh install should re-populate anything that was accidentally removed
When you install via easy_install or pip, is it completing successfully? What is the full output? Which python installation are you using? You may need to use sudo before your installation command, if you are installing modules to a system directory (if you are using the system python installation, perhaps). There's not a lot of useful information in your question to go off of, but some tools that will probably help include:
echo $PYTHONPATH and/or echo $PATH: when importing modules, Python searches one of these environment variables (lists of directories, : delimited) for the module you want. Importing problems are often due to the right directory being absent from these lists
which python, which pip, or which easy_install: these will tell you the location of each executable. It may help to know.
Use virtualenv, like #JesseBriggs suggests. It works very well with pip to help you isolate and manage the modules and environment for separate Python projects.
I had this exact problem, but none of the answers above worked. It drove me crazy until I noticed that sys.path was different after I had imported from the parent project. It turned out that I had used importlib to write a little function in order to import a file not in the project hierarchy. Bad idea: I forgot that I had done this. Even worse, the import process mucked with the sys.path--and left it that way. Very bad idea.
The solution was to stop that, and simply put the file I needed to import into the project. Another approach would have been to put the file into its own project, as it needs to be rebuilt from time to time, and the rebuild may or may not coincide with the rebuild of the main project.
I had this problem with 2.7 and 3.5 installed on my system trying to test a telegram bot with Python-Telegram-Bot.
I couldn't get it to work after installing with pip and pip3, with sudo or without. I always got:
Traceback (most recent call last):
File "telegram.py", line 2, in <module>
from telegram.ext import Updater
File "$USER/telegram.py", line 2, in <module>
from telegram.ext import Updater
ImportError: No module named 'telegram.ext'; 'telegram' is not a package
Reading the error message correctly tells me that python is looking in the current directory for a telegram.py. And right, I had a script lying there called telegram.py and this was loaded by python when I called import.
Conclusion, make sure you don't have any package.py in your current working dir when trying to import. (And read error message thoroughly).
I had a similar problem using Django. In my case, I could import the module from the Django shell, but not from a .py which imported the module.
The problem was that I was running the Django server (therefore, executing the .py) from a different virtualenv from which the module had been installed.
Instead, the shell instance was being run in the correct virtualenv. Hence, why it worked.
This Works!!!
This often happens when module is installed to an older version of python or another directory, no worries as solution is simple.
- import module from directory in which module is installed.
You can do this by first importing the python sys module then importing from the path in which the module is installed
import sys
sys.path.append("directory in which module is installed")
import <module_name>
Most of the possible cases have been already covered in solutions, just sharing my case, it happened to me that I installed a package in one environment (e.g. X) and I was importing the package in another environment (e.g. Y). So, always make sure that you're importing the package from the environment in which you installed the package.
For me it was ensuring the version of the module aligned with the version of Python I was using.. I built the image on a box with Python 3.6 and then injected into a Docker image that happened to have 3.7 installed, and then banging my head when Python was telling me the module wasn't installed...
36m for Python 3.6
bsonnumpy.cpython-36m-x86_64-linux-gnu.so
37m for Python 3.7 bsonnumpy.cpython-37m-x86_64-linux-gnu.so
I know this is a super old post but for me, I had an issue with a 32 bit python and 64 bit python installed. Once I uninstalled the 32 bit python, everything worked as it should.
I have solved my issue that same libraries were working fine in one project(A) but importing those same libraries in another project(B) caused error. I am using Pycharm as IDE at Windows OS.
So, after trying many potential solutions and failing to solve the issue, I did these two things (deleted "Venv" folder, and reconfigured interpreter):
1-In project(B), there was a folder named("venv"), located in External Libraries/. I deleted that folder.
2-Step 1 (deleting "venv" folder) causes error in Python Interpreter Configuration, and
there is a message shown at top of screen saying "Invalid python interpreter selected
for the project" and "configure python interpreter", select that link and it opens a
new window. There in "Project Interpreter" drop-down list, there is a Red colored line
showing previous invalid interpreter. Now, Open this list and select the Python
Interpreter(in my case, it is Python 3.7). Press "Apply" and "OK" at the bottom and you
are good to go.
Note: It was potentially the issue where Virtual Environment of my Project(B) was not recognizing the already installed and working libraries.

Import Error: No module named django

I am using centos linux.
I had python 2.6 with django and now i upgraded to python 2.7.
Python 2.6 is located in /usr/lib/python2.6.
Python 2.7 is located in /usr/local/lib/python2.7.
They both have site-packages directory and they both contain django 1.2.
If i run python i get the 2.7 version.
My problem is that if try to import django i get
ImportError: No module named django
I am not sure where is my PYTHONPATH defined and if this is what i need to change.
anyone ?
i ended up making a symbolic link to the 2.6 site-packages directory.
I had the same error, and this fix my issue
python -m pip install django
:) Done!
To check your path, you can use the following code:
import sys
print(sys.path)
If you already know where django is installed, it should be easy to test if the desired directory is in your path with directory in sys.path.
Regarding where your PYTHONPATH is defined, note that it's an environment variable, so you can check its value (if defined) with: echo $PYTHONPATH
Under linux, you can set the PYTHONPATH environment variable in your .profile or .bashrc. You can either edit it directly from the terminal by changing to your home directory (cd ~), and then edit the file (nano .bashrc), or by opening the file with gtkedit or vim or whatever, and add:
PYTHONPATH=/usr/local/lib/python2.7/site-packages:/another/path/etc
If you want to test this before editing your profile, you can export this from the terminal as:
export PYTHONPATH=/local/lib/python2.7/site-packages
I'm assuming you're running this straight from the command line. If you're running it as a wsgi module in apache, you can add this to your syspath from your wsgi file as:
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
try
pip freeze
this command show which packages are installed in your system
then run with root privilege
pip install django
then create a new project with command
django-admin.py startproject mysite
then start your project
cd path/to/mysite
./manage.py runserver
in file wsgi.py add this lines
import os
import sys
DJANGO_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
sys.path.append(DJANGO_PATH)
Try printing sys.path to see what's in your path. Django need to be in one of the dirs listed. Example on Windows:
>>> import sys
>>> for p in sys.path: print p
C:\Python27\Lib\idlelib
C:\Windows\system32\python27.zip
C:\Python27\DLLs
C:\Python27\lib
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages
>>>
django went missing with an upgrade to python 3.7
pip3 install django
fixed the problem.
python3 -m django --version1
for me it was that^
If you are using a environment use:
$ <environment_location>/<environment_name>/bin/python manage.py runserver
I also had same error but easily solved it .those who are using version 4 and above of Django and python 3.0 can do the following(for windows)
pip install virtualenv #installs virtual environment in pc
py -m venv myvenv #creates virtual environment named myvenv inside folder
myvenv/Scripts/activate # activates the virtual environment
You are now ready to go.
pip install django # pip install django
python -m django --version # checks the version of installed django

Categories

Resources