I'm a beginner to Django so please excuse my ignorance here. I am trying to manually install Django so that I can start working with it. I've already installed Python successfully and downloaded Django to my Mac.
When I run the command "sudo python setup.py install" in the Django-1.5.1 directory, I get the following response:
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such file or directory
Can anyone help me understand why this isn't running correctly and what I can do to fix it?
Thanks,
Ryan
As Nathan said pip or easy_install is the best way to install packages. But you need to make sure you have pip installed first:
sudo easy_install pip
sudo pip install django
If you need to specify your version of Django you can do it this way:
sudo pip install django==1.5.1
But normally it's better not to install packages globally (with sudo) and instead it's better to use virtual environments:
sudo easy_install pip
sudo pip install virtualenv
sudo pip install virtualenvwrapper
source /usr/local/bin/virtualenvwrapper.sh
mkdir myproject
cd myproject
mkvirtualenv --no-site-packages myprojectenv
workon myprojectenv
pip install django
I would suggest installing it via pip:
sudo pip install django
or easy_install:
sudo easy_install install django
Both methods will use the Python cheeseshop to install the latest version of django.
Take a look at https://docs.djangoproject.com/en/dev/topics/install/#installing-an-official-release-with-pip for more details.
Related
In my ec2 machine i need to run a django project,
I do the below thinks:
Install python 3.4:
sudo yum install python34
ok, now i create a virtual enviroment for python 3:
virtualenv -p python3 .venv3
at this point activate my venv:
source .venv3/bin/activate
all done!
Now i have to install django:
pip install django
the installation was ok but when i try to check my django version:
python -c "import django; print(django.get_version())"
system return the error "No module name django found"
How is possible?
In my machine there is also python 2.7 installed.
I try outside the virtualenv to remove django with:
sudo python -m pip uninstall django
all done, but in my .venv3 enviroment the issue is still present.
How can i fix the problem?
i also tried to reinstall django like this:
pip install --upgrade --force-reinstall django
response:
Collecting django
Using cached https://files.pythonhosted.org/packages/56/0e/afdacb47503b805f3ed213fe732bff05254c8befaa034bbada580be8a0ac/Django-2.0.6-py3-none-any.whl
Collecting pytz (from django)
Using cached https://files.pythonhosted.org/packages/dc/83/15f7833b70d3e067ca91467ca245bae0f6fe56ddc7451aa0dc5606b120f2/pytz-2018.4-py2.py3-none-any.whl
Installing collected packages: pytz, django
Found existing installation: pytz 2018.4
Uninstalling pytz-2018.4:
Successfully uninstalled pytz-2018.4
Successfully installed django-2.0.6 pytz-2018.4
but when i try:
pip freeze
response is:
gunicorn==19.8.1
pytz==2018.4
virtualenv==16.0.0
Why django isn't installed?
thanks in advance
The answer to your question depends on your version of python so you need to install pip3
sudo apt-get install python3-pip
Then, you have to create a virtual environment with venv
pip3 -p python3.6 virtualenv name
After that install Django:
pip3 install Django
As in the recent version, you can use
apt-get install python3-django
Or you can simply do the follwing:
sudo apt-get install python3 virtualenvwrapper
mkvirtualenv <venv> -p python3
workon <venv>
--system-site-packages
pip install Django
If I run pip install Django I get
Requirement already satisfied: Django in
/usr/local/lib/python2.7/dist-packages
I'd like to use python3.6 instead (which is already installed in /usr/bin/python3.6). What's the correct pip syntax to install the last version of Django on python 3.6?
You have to install pip3 :
sudo apt-get install python3-pip
Then, you have to work with venv
pip3 -p python3.6 virtualenv name
And you have to write :
pip3 install Django
#or specific version
pip3 install Django==1.10.5
If you have pip3 then directly use
pip3 install Django
Else try to use virtualenv for your python version as :
pip -p python3.6 virtualenv name
then you can install any version of Django on it.
You can install it globally as others suggested, but the recommended way to install it is to use virtualenv or venv. In case you are using virtualenv (with virtualenvwrapper), just do
mkvirtualenv --python="path to python3 executable" "environment name"
pip install django
Inside virtual environment pip would be pip3 by default and so is python.
As is common with these sort of pip issues, before you install, check where pip is pointing to with pip -V.
If that points to Python 2, you can then try pip3 -V; if that points to an older version of Python 3, go for pip3.6.
As a final approach, you can always go through python itself with python3.6 -m pip install ...
It means you already installed django in python2.7.
You can install django for python3 via:
pip3 install Django
You can also activate virtualenv, and run pip install Django
I tried to start virtualenv WITHOUT sudo but unfortunately it cannot find (Permission denied) /lib/python2.7/site-packages/easy_install.py. So I did:
sudo virtualenv name_env
The problem is that now pip is the global version (not inside pip):
which pip:
/usr/local/bin/pip
So I cannot install any package inside the environment.
If I start virtualenv without sudo:
virtualenv name_env
OSError: Command /Users/andrea/package_lambda/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error code 2
Any suggestion?
Don't use sudo just because you can!
I suggest you install another Python environment using brew, and then install pip, and subsequently virtualenv. This way, you'll substantially correct the underlying problem.
I would follow this method:
brew install pyenv
pyenv install 2.7.11
Or check the available versions through:
pyenv versions
This way, you can install different versions and switch between them as you wish, for instance:
pyenv global 2.7.11
And then you can install pip like so:
python -m easy_intall pip
and then install virtualenv like so:
python -m pip install virtualenv
As pouria mentioned, I believe it's a good idea to make sure you installed virtualenv using pip in the first place. I also agree that on OSX, using sudo should be rare.
As mentioned on a previous answer, you should also check that the files in the bin of your virtual env are correct.
I found the solution myself. I was using iterm instead of terminal (standard mac OS X). Using terminal I did:
sudo pip uninstall virtualenv
sudo pip install virtualenv
sudo cp /usr/local/bin/virtualenv /bin/virtualenv
Then I can create start a virtualenv:
virtualenv name_env
source name_env/bin/activate
To install python package on it I use:
sudo pip install --target=name_env/lib/python2.7/site-packages/ package name
I have the following file ~/.pydistutils.cfg with the contents
[install]
prefix=
temporarily removing this file fixed the issue for me (i had this file in place to address a different issue)
I am trying to get a nice clean Python environment setup on OSX 10.9. I've installed Python with Homebrew and set my PATH variables so...
> which python
/usr/local/bin/python
and
> which pip
/usr/local/bin/pip
so when I look at my /usr/local/bin :
pip -> ../Cellar/python/2.7.6/bin/pip
python -> ../Cellar/python/2.7.6/bin/python
then when I run:
> pip install virtualenv
I get permission errors on /usr/local/bin/virtualenv:
...
running install_scripts
Installing virtualenv script to /usr/local/bin
error: /usr/local/bin/virtualenv: Permission denied
I thought that by using Homebrew I could use pip and avoid using sudo to install virtualenv. Am I doing something wrong here?
Ok! I managed to fix this myself.
I deleted all the virtualenv related things from /usr/local/bin (they had been installed under root for some reason and this was causing my permission issues.).
Then I did a pip uninstall virtualenv to get rid of other instances of virtualenv, as there was still one in /usr/local/lib/python2.7/site-packages/
Then a simple pip install virtualenv and things work fine now!
Most likely HomeBrew does some magic so that running brew install allows writing to /usr/local/bin, but this privilege is not available to normal commands. This is a guess, I didn't investigate this further.
Install virtualenv with brew:
brew install pyenv-virtualenv
This command:
pip install virtualenv
runs pip from your first directory from $PATH environment variable, which is usually system wide, thus when you run in this way - you are trying to install it globall.
You should install you your environment in your $HOME directory:
virtualenv $HOME/myvirpython
and later:
$HOME/myvirpython/bin pip install something
Additionally you should read this:
https://docs.brew.sh/Homebrew-and-Python
I am trying to install twisted on python 2.6 and it seems that the Zop interface is missing.
Also it seems that it is a .egg file. I downloaded this .egg file, now how can I install it?
Install virtualenv, which includes pip. Then you can simply run:
pip install twisted
pip will handle installing the zope.interface.
Instructions for installing virtualenv and pip on OS X
This is how I installed virtualenv and pip on OS X:
curl -O http://peak.telecommunity.com/dist/ez_setup.py
sudo python ez_setup.py
sudo easy_install pip
sudo pip install virtualenv
I also like to use virtualenvwrapper with virtualenv, so I installed it using:
sudo pip install virtualenvwrapper
Instructions for installing Twisted in a virtualenv
Now to create a new virtual environment and install Twisted, I simply issue:
mkvirtualenv twisted-env
pip install twisted