Deploy Django on Python 3.6.2 - python

I have downloaded Python 3.6.2 (64 bit) in Windows 10 (64 bit). Now I want to work on Django framework so I want to download Django using pip command but it shows Error.
C:\Windows\system32>pip install django
Collecting django
Using cached Django-1.11.4-py2.py3-none-any.whl
Collecting pytz (from django)
Using cached pytz-2017.2-py2.py3-none-any.whl
Installing collected packages: pytz, django
Exception:
Traceback (most recent call last):
File "c:\program files\python36\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "c:\program files\python36\lib\site-packages\pip\commands\install.py", line 342, in run
prefix=options.prefix_path,
File "c:\program files\python36\lib\site-packages\pip\req\req_set.py", line 784, in install
**kwargs
File "c:\program files\python36\lib\site-packages\pip\req\req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "c:\program files\python36\lib\site-packages\pip\req\req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "c:\program files\python36\lib\site-packages\pip\wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "c:\program files\python36\lib\site-packages\pip\wheel.py", line 316, in clobber
ensure_dir(destdir)
File "c:\program files\python36\lib\site-packages\pip\utils\__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "c:\program files\python36\lib\os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [WinError 5] Access is denied: 'c:\\program files\\python36\\Lib\\site-packages\\pytz'

The problem has to do with the location you have chosen to install python, normally it's installed in C:\pythonXX but your installation is in C:\Program Files\pythonXX. That is always going to cause problems, you will need to always be running it as administrator. Quick and best solution, uninstall and accept to install python on the default location - C:\pythonXX

The best way to work with Django is within a virtual environment. Installing packages in your system's Python 3.6 will affect all programs you have running on Python 3.6; if you have multiple Django apps, your requirements could get all mixed up.
Django works really nicely with virtual environments: there's a good tutorial here. Essentially, you want to set up a virtual environment for each project, and then install Django (and its dependencies) cleanly within that environment. This should avoid any "Access denied" or other errors that you're experiencing.
Just as an example of how virtual environments help: if you need to use different versions of Django for different apps, they should be limited only to apps within that same virtual environment. Then, you can install the package differently in a different environment for another app. That way, when you "import django" from one of your apps, you know you're getting the version you need.

Related

I cannot install sklearn, numpy, and scipy on Windows 10 command Prompt to use on Python 3.6

I have Python 3.6 correctly installed and have been working on Eclipse. But I cannot use the libraries. Every time I import them I get an error message:
Traceback (most recent call last):
File "C:\Users\gilbe\eclipse-workspace\python3.6\BeginnerFiles\IrisDataSet", line 1, in <module>
from sklearn import datasets
ModuleNotFoundError: No module named 'sklearn'`
When I tried installing sklearn, numpy, and scipy, I type in the following into Windows Command Prompt:
"pip install numpy", "pip install scipy", or "pip install sklearn".
However, I get an error message every time. For example:
C:\Program Files (x86)\Python36-32\Scripts>pip install sklearn
Collecting sklearn
Using cached https://files.pythonhosted.org/packages/1e/7a/dbb3be0ce9bd5c8b7e3d87328e79063f8b263b2b1bfa4774cb1147bfcd3f/sklearn-0.0.tar.gz
Collecting scikit-learn (from sklearn)
Using cached https://files.pythonhosted.org/packages/87/b7/0e7f5c0cf765cf4e1924c068e7b2e1708c93ebffde9302a57ea8f26619e9/scikit_learn-0.19.1-cp36-cp36m-win32.whl
Installing collected packages: scikit-learn, sklearn
Exception:
Traceback (most recent call last):
File "c:\program files (x86)\python36-32\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\commands\install.py", line 342, in run
prefix=options.prefix_path,
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_set.py", line 784, in install
**kwargs
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "c:\program files (x86)\python36-32\lib\site-packages\pip\wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\wheel.py", line 316, in clobber
ensure_dir(destdir)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\utils\__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "c:\program files (x86)\python36-32\lib\os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [WinError 5] Access is denied: 'c:\\program files (x86)\\python36-32\\Lib\\site-packages\\scikit_learn-0.19.1.dist-info'
You are using pip version 9.0.3, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Further, when I try to upgrade the pip command using the suggested command above, I also get an error message:
C:\Program Files (x86)\Python36-32\Scripts>python -m pip install --upgrade pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 9.0.1
Uninstalling pip-9.0.1:
Exception:
Traceback (most recent call last):
File "C:\Program Files\Inkscape\python\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\Program Files\Inkscape\python\lib\site-packages\pip\commands\install.py", line 342, in run
prefix=options.prefix_path,
File "C:\Program Files\Inkscape\python\lib\site-packages\pip\req\req_set.py", line 778, in install
requirement.uninstall(auto_confirm=True)
File "C:\Program Files\Inkscape\python\lib\site-packages\pip\req\req_install.py", line 754, in uninstall
paths_to_remove.remove(auto_confirm)
File "C:\Program Files\Inkscape\python\lib\site-packages\pip\req\req_uninstall.py", line 115, in remove
renames(path, new_path)
File "C:\Program Files\Inkscape\python\lib\site-packages\pip\utils\__init__.py", line 267, in renames
shutil.move(old, new)
File "C:\Program Files\Inkscape\python\lib\shutil.py", line 303, in move
os.unlink(src)
WindowsError: [Error 5] Access is denied: 'c:\\program files\\inkscape\\python\\lib\\site-packages\\pip-9.0.1.dist-info\\description.rst'
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
My real question here is how do I fix these issues, and install these libraries correctly, I have spent a whole day trying to fix this in different ways, including: installing the libraries from inside Eclipse, through Window>Preferences>Interpreter>Python Interpreter>Install with pip
, Uninstalling and Reinstalling Python, attempting to use the easy_install <package> command.
Please help.
right click on the windows button on bottom left of your screen.
Then go to "Windows PowerShell(Admin).
There you try your pip installs. It will definitely work. I think you don't have the admin access that is why you are seeing.
PermissionError: [WinError 5] Access is denied
Just open the cmd with admin as user.Hope this helps.

Install module 'requests' on python 3.5.1 mac [duplicate]

This question already has an answer here:
Installing pip on Mac OS error - Permission denied: '/Library/Python/2.7/site-packages/pip'
(1 answer)
Closed 6 years ago.
I am very new to python and have recently installed python 3.5.1 and am trying to install the module 'requests' by writing the following in terminal:
pip install requests
However I am receiving the following error. Thank you so much in advance for any help that you can give!
Collecting requests
Using cached requests-2.9.1-py2.py3-none-any.whl
Installing collected packages: requests
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-8.1.0-py2.7.egg/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-8.1.0-py2.7.egg/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip-8.1.0-py2.7.egg/pip/req/req_set.py", line 732, in install
**kwargs
File "/Library/Python/2.7/site-packages/pip-8.1.0-py2.7.egg/pip/req/req_install.py", line 835, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Python/2.7/site-packages/pip-8.1.0- py2.7.egg/pip/req/req_install.py", line 1030, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip-8.1.0-py2.7.egg/pip/wheel.py", line 344, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-8.1.0-py2.7.egg/pip/wheel.py", line 315, in clobber
ensure_dir(destdir)
File "/Library/Python/2.7/site-packages/pip-8.1.0- py2.7.egg/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/requests'
You're attempting to install requests to a place you do not have permissions to do so.
If you sudo it, ie. sudo pip install requests it will succeed. Else you can look into virtual environments to manage dependancies locally.
Also, you're installing the Python 2.7.x version of requests, due to using the Python 2.7.x version of pip. You'll need to use the pip for 3.5 explicitly if that's the one you want to install. There will either be a pip3.5 binary, or you can launch it with the full path to pip for Python 3.5.x

How to make pip work?

I cant figure out how to get pip to work for me. I have python 3.5.1 and I run
import pip
pip.main(['install', 'psutil'])
and get an error saying "AttributeError: module 'pip' has no attribute 'main'".
Im just wondering what I need to do for pip to work
EDIT
My code was named pip.py so I renamed it now when it runs I get this
Collecting
psutil
Using cached psutil-4.0.0-cp35-none-win32.whl
Installing collected packages: psutil
Exception:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\basecommand.py", line 211, in main
status = self.run(options, args)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\commands\install.py", line 311, in run
root=options.root_path,
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\req\req_set.py", line 646, in install
**kwargs
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\req\req_install.py", line 803, in install
self.move_wheel_files(self.source_dir, root=root)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\req\req_install.py", line 998, in move_wheel_files
isolated=self.isolated,
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\wheel.py", line 339, in move_wheel_files
clobber(source, lib_dir, True)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\wheel.py", line 310, in clobber
ensure_dir(destdir)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pip\utils\__init__.py", line 71, in ensure_dir
os.makedirs(path)
File "C:\Program Files (x86)\Python35-32\lib\os.py", line 241, in makedirs
mkdir(name, mode)
PermissionError: [WinError 5] Access is denied: 'C:\\Program Files (x86)\\Python35-32\\Lib\\site-packages\\psutil'
You are using pip version 7.1.2, however version 8.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
You called your script pip.py or you have a file in your path that is called pip.py so you are importing from that not the pip module. Use pip.__file__ to see where the file is and either rename or remove it, making sure to remove any .pyc file with the same name.
The PermissionError makes this fairly obvious. C:\Program Files (x86) (and all sub-directories) have permissions set such that only Administrators can write to them (for security reasons).
You need to run your script from an administrative command prompt, or otherwise run it with admin privileges. For example, in the Start Menu search box, type cmd.exe, right click the result, and select "Run as administrator". Running your script from within the elevated prompt should install normally.

OSError: [Errno 13] Permission denied when installing django

I am on ubuntu 14.04 freshly installed, and I have installed pip and virtualenvironment but when I try to install django I get the following error message:
name#computername:/$ pip install django
Collecting django
Using cached Django-1.7.4-py2.py3-none-any.whl
Installing collected packages: django
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pip-6.0.7-py2.7.egg/pip/basecommand.py", line 232, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/dist-packages/pip-6.0.7-py2.7.egg/pip/commands/install.py", line 347, in run
root=options.root_path,
File "/usr/local/lib/python2.7/dist-packages/pip-6.0.7-py2.7.egg/pip/req/req_set.py", line 549, in install
**kwargs
File "/usr/local/lib/python2.7/dist-packages/pip-6.0.7-py2.7.egg/pip/req/req_install.py", line 740, in install
self.move_wheel_files(self.source_dir, root=root)
File "/usr/local/lib/python2.7/dist-packages/pip-6.0.7-py2.7.egg/pip/req/req_install.py", line 949, in move_wheel_files
isolated=self.isolated,
File "/usr/local/lib/python2.7/dist-packages/pip-6.0.7-py2.7.egg/pip/wheel.py", line 234, in move_wheel_files
clobber(source, lib_dir, True)
File "/usr/local/lib/python2.7/dist-packages/pip-6.0.7-py2.7.egg/pip/wheel.py", line 205, in clobber
os.makedirs(destdir)
File "/usr/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/django'
It does, however work when I try installing on a venv.
Could this have anything to do with $PYTHONPATH?
(I believe this is also causing conflicts when I try to run runserver on an already started project. But I will leave that for another question if this one doesn't resolve it.)
You need to activate your virtual environment first.
$ source PATH_TO_ENV/bin/env
$ pip install django
In a newly created virtualenv there will also be a activate shell script. For Windows systems, activation scripts are provided for the Command Prompt and Powershell.
On Posix systems, this resides in /ENV/bin/
Unless you do this you are using system python and system libs. That's why you see the error.
If you need to install a lib into the system scope you need root access:
$ sudo pip install django

Update to Django 1.7 with pip

I updated from Django 1.5.8 to 1.7:
pip install Django==1.7
Downloading/unpacking Django==1.7
Downloading Django-1.7-py2.py3-none-any.whl (7.4MB): 7.4MB downloaded
Installing collected packages: Django
Found existing installation: Django 1.5.8
Uninstalling Django:
Successfully uninstalled Django
Rolling back uninstall of Django
Cleaning up...
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/commands/install.py", line 283, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 1435, in install
requirement.install(install_options, global_options, *args, **kwargs)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 671, in install
self.move_wheel_files(self.source_dir, root=root)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 901, in move_wheel_files
pycompile=self.pycompile,
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line 247, in move_wheel_files
clobber(source, dest, False, fixer=fixer, filter=filter)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line 209, in clobber
shutil.copy2(srcfile, destfile)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 130, in copy2
copyfile(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 83, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/usr/local/bin/django-admin.py'
Storing debug log for failure in /Users/stefanieness/Library/Logs/pip.log
This is my error message.
But when I run
python
import django
print(django.get_version())
I get 1.7. Can I use the version like that or do I have to reinstall it? Will it work?
Thank you!
This is because the first time you installed django, you did sudo pip install django, which has installed django in your global Python interpreter as the root user (or the superuser).
You can only have one version of django in your global Python interpreter, so once you upgrade it, any of your django applications that are using the global Python interpreter (in other words, not using a virtual environment) will be automatically upgraded to 1.7
If you don't have any other django projects, then this doesn't really have any negative effects - but as a best practice, you should use virtual environments so that you can easily test versions of libraries.
To solve your immediate problem, you need to sudo pip install -U django which will upgrade django to the latest stable release.

Categories