I tried both admin-django, and admin-django.py, but it just tells me that it can't find the command. I use Arch Linux and installed python-django with pacman. I also tried to set $PATH to /usr/local/bin, how someone on SO suggested, but it didn't help. Would anyone here know what I could have done wrong?
(python -c "import django" works)
Installing Python packages via your OS package manager is really hit or miss. It's likely that their setup script wasn't configured correctly (or, is an old version that doesn't match the documented behavior). You should follow the installation instructions and use pip instead -- it should be safe to download pip from your package manager, and then use it for all of your Python packages after that.
Also, their documentation mentions that the command is django-admin.py, not admin-django.py, but, since your title is correct, I assume that was a typo.
in effet you should use the command django-admin in this way
django-admin startproject _the_name_of_your_project
if tell you " command not found "
Maybe you should consider to reinstall django :
sudo pip uninstall
Best Practice : Use venv
sudo pip install virtualenv
Go in your working directory :
source env/bin/ activate
Now you are in a virtual enviroment :
sudo pip install django
Try the command django-admin
Related
I tried to configure my PC for Django course , i have fresh Ubuntu 18.04 :
I followed all steps from the course :
I had newest python pre-installed, Python 3.6.5 so i went :
sudo apt install python3-pip
went ok, then :
pip3 install django==2.0.2 (version suggested by instructor)
that completed as well, then :
django-admin startproject wordcount
and that gave me error :
Command 'django-admin' not found, but can be installed with:
sudo apt install python-django-common
So i tried to install this but it didn't help. so i checked web for answers and i found that i should do :
sudo apt-get install python-django
And after that i could use
django-admin startproject wordcount
and it created a project for me but i saw that some elements of default files are different from what i saw on course video so i check and :
django-admin --version
1.11.11
also django-admin --help
gives me message like this :
Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.).
Any ideas what went wrong and how I can fix it?
The problem is that the pip3-installed packages aren't on the PATH for some reason. There's a few ways to fix this.
Add the pip3 installation location to your $PATH.
Force it to use the version of Django you installed via pip3:
$ python3 -m django.bin.django-admin startproject wordcount
Use virtualenv or pipenv to create a "virtual" Python installation - complete with it's own Python version and set of libraries.
I see you struggle with this problem. I would recommend you to move to such thing as a virtualenv (or use anaconda for this task). This should solve a numerous other problems you've not ran across yet and this one especially.
Virtual environment allows you to create separate environment, with it's own packet set. Some IDEs (for example, pycharm) provide GUI for it's creation and management.
Update 1:
Thanks to #DhavalSavalia, of course there is also pipenv package, that is a more friendly virtualenv wrapper (unless you have some gui for virtualenv).
Update 2:
Also, I've noticed that you setting up django using apt. You probably shouldn't do that, because apt often contains old version of python packages. Use pip for as many packages as you can.
I use Ubuntu 15.10 and zsh (don't know if it can help)
So I try to install django:
pip install django
Downloading/unpacking django
Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded
Installing collected packages: django
Successfully installed django
Cleaning up...
Everything works fine. When I do pip freeze I can see django is installed.
then:
django-admin startproject mysite
But I got this issue:
zsh: command not found: django-admin
I found an alternative solution.
With find / -name django-admin I found django-admin in myHome/.local/bin/django-admin.
So instead of django-admin startproject mysite I use the full path myHome/.local/bin/django-admin startproject mysite
thanks to #Evert, this is why I got the problem.
his comment:
This is likely because you either used the --user option to pip
install, or you set up pip in such a way that it automatically does
that. Hence, everything gets installed in $HOME/.local. You may want
to add $HOME/.local/bin to your $PATH for the future.
When I had the problem on my mac I just uninstall django and install it again but with root permissions. Now it's working good)
pip3 uninstall django
sudo pip3 install django
I faced a similar issue on Mac OS but I moved in another way. I used Virtual Environments.
First, create the virtual environment
python3 -m venv django-env
Then, use this environment
source django-env/bin/activate
Next, install django
python -m pip install django
Finally test django is working
django-admin startproject mysite
In my opinion, it is better to have environments isolated to avoid O.S. settings
I was facing the same problem after updating my Mac OS to Catalina, and shell from bash to zsh.
None of the commands would work, as if all my paths were deleted.
Looking at Brady Huang's answer, doing something similar worked for me.
I made sure django was installed correctly by reinstalling it
pip3 uninstall django
pip3 install django
I found django installed under:
/Library/Frameworks/Python.framework/Versions/3.8/bin/django-admin
by running:
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.8/bin/django-admin usr/local/bin
I was able to run django-admin again.
My adjango-admin is located in
~/Library/Python/3.7/bin/django-admin
But I don't have it in my linked PATH which is looks like this
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin
So I create a symlink to one of the bin I have in my PATH
sudo ln -s ~/Library/Python/3.7/bin/django-admin /usr/local/bin
It solves my issue
You may be having some dependency issues.
So to avoid it happen again you need to create a virtual environment only for the current project you are doing. Like this you can avoid having issues and isolate your application.
You can follow this question to create a virtual environment and add django in it.
Then, as soon as you create the virtual environment and activated you can pip install django and check to see whether it is installed.
Tried many stuffs but then installing the python version 3.11 and using a virtual env solved the issue. Earlier I was using 3.8.9. Hope this helps someone
what worked for me!
I just Added the following in my ~/.zshrc file( you can also add it in the ~/.bashrc file if you are not using zsh terminal)
export PATH=$PATH:$HOME/.local/bin
This solution will work not only for you django-admin command but all other python package commands that would behave in a similar way.
I'm still getting familiar with python and python eggs so sorry if this is a stupid question. I want to know why easy_install appears to install the egg for the whole server to use rather than just locally for the account that tried to install it.
I created a simple helloworld module/egg and tried to install it on a server I have an account on. However, the account doesn't have root access (it's a tester's account). I get a "Permission denied" error message when installing it. When installing the module, it is trying to install to /usr/local/lib/python2.7/site_packages/blah/blah/blah. It's pretty clear it's b/c I don't have root access to write to this location.
easy_install hello-1.0-py2.7.egg
On my laptop (my account has root access), I can run the cmd above and see the module is installed by running 'pip freeze'. The slight difference is that Anaconda is running/installed on my laptop and seemed to be doing the package management for me.
So back to my original question; how does easy_install install eggs that we create ourselves? I was hoping/assuming it would install the module in my tester's account and not to /usr/local/lib/blha/blah/blah for all users to use/access. Is this an incorrect assumption? If this is incorrect thinking, how would someone install a module/egg where the account doesn't have root access? Thanks.
Se per easy_install or pip as a limited user? you'll want to use the --prefix option to easy_install and/or -d or -s.
I believe you could do something as simple as:
easy_install --prefix=$HOME hello-1.0-py2.7.egg
An option is to use virtualenv which allows you to create multiple virtual environments for Python, each with its own set of libraries.
Just create a virtualenv and then you can then install your module within it without requiring write access to the system Python installation.
There is a tutorial here: http://simononsoftware.com/virtualenv-tutorial/, but simply install virtualenv then:
$ cd $HOME
$ virtualenv test
$ cd test
$ source bin/activate
$ easy_install /path/to/hello-1.0-py2.7.egg
The package should be installed into ~/test/lib/python2.7/site-packages
I'm trying to install the following as per the learnpythonthehardway tutorial:
pip from http://pypi.python.org/pypi/pip
distribute from http://pypi.python.org/pypi/distribute
nose from http://pypi.python.org/pypi/nose/
virtualenv from http://pypi.python.org/pypi/virtualenv
I've visited these links and clicked the download button; each file is in my downloads folder now, and I unarchive/unzipped them- not sure what this means but it seemed required. Are they "installed"? If not, what does it mean to really install them? I've tried typing nosetests in the terminal (as the book says you should), as well as tried easy_install but that doesn't seem to work. It appears my understanding is limited in a number of ways here.
I get the following -bash: nosetests: command not found, but am trying to get:
nosetests . ---------------------------------------------------------------------- Ran 1 test in 0.007s
OK
This works on mac, it may work on linux
1)Open terminal (Be prepared to enter your password)
2)Type: sudo easy_install pip
3)Type: sudo pip install distribute
4)Type: sudo pip install nose
5)Type: sudo pip install virtualenv
Hope that helps, cheers!
They are not yet installed.
Each has its own vagaries about how exactly the install process works and in fact some of those packages will include the other packages with them. I.e.
"If you use virtualenv, a copy of pip will be automatically be
installed in each virtual environment you create."
http://pypi.python.org/pypi/pip
As a relatively new python user myself, (and having gone thru a similar process not long ago) I am eagerly awaiting the more complete answers that come back for this one.
Find out where the nosetests script is. On OSX:
/usr/local/share/nosetests
Execute directly, or set up a bash alias, perhaps in .bash_profile:
alias nosetests='/usr/local/share/python/nosetests'
alias nosetests3='/usr/local/share/python3/nosetests'
You were on the right track, but the package is actually called "nose". The documentation for nose (nosetests is the script) can be found here:
https://nose.readthedocs.org/en/latest/
The short answer is that you have 2 basic options: easy_install or pip. Install using setuptools/distribute: easy_install nose. Install using pip: pip install nose
Install Python 2.7 and after just do this (only on Windows - Windows PowerShell):
Setup PATH env:
C:\Python27\;C:\Python27\Scripts\", "User"
pip is already installed
3.
.\pip install distribute
4.
.\pip install nose
5.
.\pip install virtualenv
I've installed virtualenv via pip and get this error after creating a new environment:
selenium:~ auser$ virtualenv new
New python executable in new/bin/python
ERROR: The executable new/bin/python is not functioning
ERROR: It thinks sys.prefix is u'/System/Library/Frameworks/Python.framework/ Versions/2.6' (should be '/Users/user/new')
ERROR: virtualenv is not compatible with this system or executable
In my environment:
PYTHONPATH=/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
PATH=/System/Library/Frameworks/Python.framework/Versions/2.6/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
How can I repair this?
Thanks.
Just in case there's someone still seeking for the answer.
I ran into this same problem just today and realized since I already have Anaconda installed, I should not have used pip install virtualenv to install virtual environment as this would give me the error message when trying to initiate it later. Instead, I tried conda install virtualenv then entered virtualenv env_mysite and problem solved.
Like #RyanWilcox mentioned, you might be inadvertently pointing virtualenv to the wrong Python installation. Virtualenv comes with a -p flag to let you specify which interpreter to use.
In my case,
virtualenv test_env
threw the same error as yours, while
virtualenv -p python test_env
worked perfectly.
If you call virtualenv -h, the documentation for the -p flag will tell you which python it thinks it should be using; if it looks wonky, try passing -p python. For reference, I'm on virtualenv 1.11.6.
In case anyone in the future runs into this problem - this is caused by your default Python distribution being conda. Conda has it's own virtual env set up process but if you have the conda distribution of python and still wish to use virtualenv here's how:
Find the other python distribution on your machine: ls -ls /usr/bin/python*
Take note of the availble python version that is not conda and run the code below (note for python 3 and above you have to upgrade virtualenv first): virtualenv -p python2.7(or your python version) flaskapp
I've run across this problem myself. I wrote down the instructions in a README, which I have pasted below....
I have found there are two things that work:
Make sure you're running the latest virtualenv (1.5.1, of this writting)
If you're using a non system Python as your standard Python (which python to check) Forcefully use the System supplied one.
Instead of virtualenv thing use /usr/bin/python2.6 PATH/TO/VIRTUALENV thing (or whatever which
python returned to you - this is what it did for me when I ran into this issue)
I had the same problem and as I see it now, it was caused by a messy Python installation. I have OS X installed for over a year since I bought a new laptop and I have already installed and reinstalled Python for several times using different sources (official binaries, homebrew, official binaries + hand-made adjustments as described here). Don't ask me why I did that, I'm just a miserable newbie believing everything will fix itself after being re-installed.
So, I had a number of different Pythons installed here and there as well as many hardlinks pointing at them inconsistently. Eventually I got sick of all of them and reinstalled OS X carefully cleaned the system from all the Pythons I found using find utility. Also, I have unlinked all the links pointing to whatever Python from everywhere. Then I've installed a fresh Python using homebrew, installed virtualenv and everything works as a charm now.
So, my recipe is:
sudo find / -iname "python*" > python.log
Then analyze this file, remove and unlink everything related to the version of Python you need, reinstall it (I did it with homebrew, maybe official installation will also work) and enjoy. Make sure you unlink everything python-related from /usr/bin and /usr/local/bin as well as remove all the instances of Frameworks/Python.framework/Versions/<Your.Version> in /Library and /System/Library.
It may be a dirty hack, but it worked for me. I prefer not to keep any system-wide Python libraries except pip and virtualenv and create virtual environments for all of my projects, so I do not care about removing the important libraries. If you don't want to remove everything, still try to understand whether your Pythons are, what links point to them and from where. Then think what may cause the problem and fix it.
I ran into a variation of this "not functioning" error.
I was trying to create an environment in a folder that included the path ".../Programming/Developing..." which is actually "/Users/eric/Documents/Programming:Developing/"
and got this error:
ImportError: No module named site
ERROR: The executable env/bin/python2.7 is not functioning
ERROR: It thinks sys.prefix is u'/Users/eric/Documents/Programming:Developing/heroku' (should be u'/Users/eric/Documents/Programming:Developing/heroku/env')
ERROR: virtualenv is not compatible with this system or executable
I tried the same in a different folder and it worked fine, no errors and env/bin has what I expect (activate, etc.).
I got the same problem and I found that it happens when you do not specify the python executable name properly. So for python 2x, for example:
virtualenv --system-site-packages -p python mysite
But for python 3.6 you need to specify the executable name like python3.6
virtualenv --system-site-packages -p python3.6 mysite
On on OSX 10.6.8 leopard, after having "upgraded" to Lion, then downgrading again (ouch - AVOID!), I went through the Wolf Paulus method a few months ago, completely ignorant of python. Deleted python 2.7 altogether and "replaced" it with 3.something. My FTP program stopped working (Fetch) and who knows what else relies on Python 2.7. So at that point I downloaded the latest version of 2.7 from python.org and it's installer got me up and running - until i tried to use virtualenv.
What seems to have worked for me this time was totally deleting Python 2.7 with this code:
sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7
removing all the links with this code:
sudo rm /usr/bin/pydoc
sudo rm /usr/bin/python
sudo rm /usr/bin/pythonw
sudo rm /usr/bin/python-config
I had tried to install python with homebrew, but apparently it will not work unless all of XTools is installed, which I have been avoiding, since the version of XTools compatible with 10.6 is ancient and 4GB and mostly all I need is GCC, the compiler, which you can get here.
So I just installed with the latest download from python.org.
Then had to reinstall easy_install, pip, virtualenv.
Definitely wondering when it will be time for a new laptop, but there's a lot to be said for buying fewer pieces of hardware (slave labor, unethical mining, etc).
The above solutions failed for me, but the following worked:
python3 -m venv --without-pip <ENVIRONMENT_NAME>
. <ENVIRONMENT_NAME>/bin/activate
curl https://bootstrap.pypa.io/get-pip.py | python
deactivate
It's hacky, but yes, the core problem really did just seem to be pip.
I did the following steps to get virtualenv working :
Update virtualenv as follows :
==> sudo pip install --upgrade virtualenv
Initialize python3 virtualenv :
==> virtualenv -p python3 venv
I had this same issue, and I can confirm that the problem was with an outdated virtualenv.py file.
It was not necessary to do a whole install --upgrade.
Replacing the virtualenv.py file with the most recent version sufficed.
I also had this problem, and I tried the following method which worked for me:
conda install virtualenv
virtualenv --system-site-packages /anaconda/envs/tensorflow (here envs keeps all the virtual environments made by user)
source /anaconda/envs/tensorflow/bin/activate
Hope it's helpful.
I had this same issue when trying to install py2.7 on a newer system. The root issue was that virtualenv was part of py3.7 and thus was not compatible:
$ virtualenv -p python2.7 env
Running virtualenv with interpreter /usr/local/bin/python2.7
New python executable in /Users/blah/env/bin/python
ERROR: The executable /Users/blah/env/bin/python is not functioning
ERROR: It thinks sys.prefix is u'/Library/Frameworks/Python.framework/Versions/2.7' (should be u'/Users/blah/env')
ERROR: virtualenv is not compatible with this system or executable
$ which virtualenv
/Library/Frameworks/Python.framework/Versions/3.7/bin/virtualenv
# install proper version of virtualenv
$ pip2.7 install virtualenv
$ /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv -p python2.7 env
$ . ./env/bin/activate
(env) $
Open terminal and type /Library/Frameworks/Python.framework/Versions/
then type ls /Library/Frameworks/Python.framework/Versions/2.7/bin/
if you are using Python2(or any other else).
Edit ~/.bash_profile and add the following line:
export PATH=$PATH:/Library/Frameworks/Python.framework/Versions/2.7/bin/
cat ~/.bash_profile
In my case the content of ~/.bash_profile is as follows:
export PATH=$PATH:/Library/Frameworks/Python.framework/Versions/2.7/bin/
Now the virtualenv command should work.
If you continue to have trouble with virtualenv, you might try pythonbrew, instead. It's an alternate solution to the same problem. It works more like Ruby's rvm: It builds and creates an entire instance of Python, under $HOME/.pythonbrew, and then sets up some bash functions that allow you to switch easily between versions. Where virtualenv shadows the system version of Python, using symbolic links as part of its solution, pythonbrew builds entirely self-contained installations of Python.
I used virtualenv for years. It's a decent solution, but I've switched to pythonbrew lately. Having completely self-contained Python instances means that installing a new one takes awhile (since pythonbrew actually compiles Python from scratch), but the self-contained nature of each installation appeals to me. And disk is cheap.