pyvenv & pip not installing into local site-packages - django

I'm test driving the Django 1.6b, Python 3.3.2 (compiled from source) and pyvenv with Ubuntu 12.04.
Every time I try and install perform a pip install [package] the package attempts to install itself globally rather than into my local environment. A simple workflow is as follows:
$ pyvenv environments/roebk
$ source environments/roebk/bin/activate
$ (roebk) pip install south
error: could not create '/usr/local/lib/python3.3/site-packages/south': Permission denied
I've double checked that I'm using the correct version of pip.
$ pip -V
pip 1.4 from /usr/local/lib/python3.3/site-packages/pip-1.4-py3.3.egg (python 3.3)
Am I missing anything obvious?

Did you install setuptools and pip into the environment? virtualenv installs setuptools and pip automatically into a new environment.
$ virtualenv qwerty
New python executable in qwerty/bin/python
Installing setuptools............done.
Installing pip...............done.
$
According to the pyvenv docs you need to install them into the new environment manually.
Common installation tools such as Distribute and pip work as expected
with venvs - i.e. when a venv is active, they install Python packages
into the venv without needing to be told to do so explicitly. Of
course, you need to install them into the venv first: this could be
done by running distribute_setup.py with the venv activated, followed
by running easy_install pip. Alternatively, you could download the
source tarballs and run python setup.py install after unpacking, with
the venv activated.

Upon the official docs I thought Python 3.4 would install pip automatically, but it seems, it doesn't:
Changed in version 3.4: Installs pip by default, added the --without-pip and --copies options
EDIT: Somehow I managed to use a Python3.3.2 version also installed on that machine. With Python3.4, it works as expected.

Related

Trying to install Pyramid package with "python setup.py install" gives error searching for a package

I'm working on a Pyramid project that has to be deployed in a Debian 7 server.
The Debian 7 server has the python version 2.7.3 as from the archives repositories.
After creating a virtual environment with virtualenv command the pip version installed in this virtualenv is 1.1.
First thing noted: I can't upgrade pip with pip install --upgrade pip. The version is not updated and remains in 1.1 version.
After installing the OS packages needed to install the project I ran python setup.py install but I get the error:
Searching for zipp==0.5
Reading http://pypi.python.org/simple/zipp/
Couldn't find index page for 'zipp' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for zipp==0.5
error: Could not find suitable distribution for Requirement.parse('zipp==0.5')
So, the python setup.py install command could not recognize the zipp package.
I thought that this was related to the older version of pip (1.1). So I could update pip version successfully using the index-url option:
$ pip install --index-url https://pypi.python.org/simple --upgrade pip
That updated pip version from 1.1 to 20.3b1. Then I tried python setup.py install again, but the same error occurred.
What I could see is that, after updating pip version, the zipp==0.5.0 package is installed if I ran pip install zipp==0.5.
I'm new to Pyramid and the package installing using the setup.py module. I'm not understanding why I can install the zipp package with pip and can't with python setup.py install.
I'm not putting the content of setup.py here because I think it's not a problem of the setup.py script. With more recent versions of python and pip in an Ubuntu 18.04 machine the setup.py works like a charm.
Someone could explain how to solve this issue?
When you run python setup.py install directly, you are not using pip, so the version of pip you have installed is irrelevant. This command is antiquated, should not be used, etc, etc. The right answer is to use pip install . as a replacement for python setup.py install and to use pip install -e . as a replacement for python setup.py develop.
With respect to what you're seeing, when you run python setup.py install this using the version of easy_install bundled with setuptools to talk to PyPI and install dependencies. This should be avoided for a lot of reasons but just know that to override urls it uses they go in ~/.pydistutils.cfg and have nothing to do with pip. HTTPS is one problem that you looked at, another is that old versions of Python do not have the right CA trust store, nor support the minimum required TLS 1.2 to handshake with PyPI. So expect lots of problems using old tools - at the very least try to use pip instead of easy_install.

How to install Pip on a new Ubuntu upgrade

I posted the question below, but none of the answers I was pointed to worked, though they look like they should.
I activated (again) the virtualenv. It still tells me that pip can't be found by apt when doing an 'apt install' command. But here is where I am now, and very confused.
I pointed my directory to "/home/.../q7root/bin/pip" and did an "ls". It shows a sub-directory with pip in it (or, I think, a link to it - I'm not the best at Unix). When I type "which pip" I get the path to this point ('q7root/pip'). bit if I just type "pip" at the CLI I get I get this error:
[![pip error][1]][1]
I have looked at my PATH, and this q7root/bin is the first place to look on the path. And, despite trying mightily with all the references people gave me, pip3 never gets installed.
But even pip is challenged. "which pip" points to this copy in the virtual environment site, but typing "pip" as a command tells me 'No module named pip.'
So pip seems to need more stuff installed (?), or there is some mess. Any advice?
Original Question:
At the suggestion of others working on what was a functional Django project, I upgraded to a more recent version of Ubuntu (18).
However, when I first try to run it it blows up at line 3 of the initial script module when asked to import django as a package.
I tried pip -r requirements.txt, but the system said pip was an unknown package. I dropped down and used apt to load pip onto my machine (sudo apt-get pip), then tried using pip itself (pip update pip) which failed.:
[![Pip load error message][2]][2]
I also tried pip install django, and got this:
[![django not found][3]][3]
I would have thought an OS upgrade would not require re-installing all currently installed packages (seems like a no-brainer to do the work of installing everything that had been installed). But right now I am terribly stuck...obviously, having 'pip' let's you (at least) have a basic CLI tool.
Any advice?
[1]: https://i.stack.imgur.com/OPfgc.png
[2]: https://i.stack.imgur.com/shLOc.png
[3]: https://i.stack.imgur.com/bEhDB.png
It depends on the version of python.
Python 3
sudo apt update
sudo apt install python3-pip
Python 2
sudo apt update
sudo apt install python-pip
How to Install Pip on Ubuntu 18.04
Start with a fresh Ubuntu install. I think you've run too many commands for your current setup to be reproduceable.
Install python3 and python3-venv.
sudo apt update
sudo apt install python3 python3-venv
Use the venv module to create the virtual env.
python3 -m venv myenv
source myenv/bin/activate
You now have access to pip in the venv.
It's OK to upgrade pip in the virtual env, I suggest you don't ever upgrade the system pip otherwise you might hit issues like this.
(myenv) python -m pip --version
(myenv) python -m pip install --upgrade pip
Now you can use pip to install your requirements in the virtual env.
(myenv) python -m pip install -r requirements.txt
In the above commands I've used python -m pip instead of pip. This is the recommended way, as it ensures that you are using the version of pip that matches python.
In the end, this was a state of deep computer confusion. I was already disk-limited so I bought a new computer, and this error did not recur with the same code being used.

django update version without pip

I want to update my django version (1.8 ->1.9).
My current version was installed using pip (pip install Django) .
Now I need to install a newer version without pip.
I think I should run from the django package folder, using the setup.py file:
python setup.py install
[I've installed some other packages using a setup.py file .]
The question - will that create some problems? And, does the setup.py install method take care for uninstalling the older version? Or I have to uninstall manually somehow?
I don't have internet connection in this computer, so no pip.
Download a release (they are available on GitHub), and copy to your computer.
Then use pip install to install the archive. For example
pip install django-1.9.3.tar.gz
For more ways to use pip install, see the docs.

Why does apt-get install django 1.6.1 on Ubuntu 14.04?

I just set up a new Ubuntu 14.04 and installed django using apt-get. Now django is installed in version 1.6.1 which is an insecure and unsupported version. The end of the extended support was April 2015 (https://www.djangoproject.com/download/) so I don't see why there is such an old version in the official apt-get.
Is there a good reason for this behaviour?
I think apt-get repository is not updated for django
Instead of using apt-get use pip to install Django(sudo pip install django). You shoud use virtualenv to run more than one python apps. Suppose you want to run more one applications,(hosting more than one django websites of different version or requirements.), run you applications in different virtualenv. Different applications may have different reuirements or version.
It's easy to install:
Install Virtualenv
$ pip install virtualenv
$ pip install virtualenvwrapper
$ source virtualenvwrapper.sh
$ mkvirtualenv virtualenv_name // create virtualenv
$ workon virtualenv_name
To restart virtalenv later
Run:
$ source virtualenvwrapper.sh
$ lsvirtualenv // list all virtual env
$ workon virtualenv_name // start working on virtual env
Now install you requirements on virtualenv.
$ pip install django==1.8
Try to learn here
http://www.tangowithdjango.com/book17/chapters/requirements.html#virtual-environments

Django not installed in venv?

Would anyone know possible reasons why Django is being installed in the global site package and not my venv's site package folder?
Here's my set up and what I did, this is a bit detailed since I'm new to Python/Django and not sure which information is important:
Python 3.3 is installed in c:\python33
I have virtualenv, pip, easy_install installed in C:\Python33\Scripts.
My venv is c:\users\username\projects\projB
This venv was created using pyvenv, not virtualenv.
I activated the venv.
I changed directory to C:\Python33\Scripts to run "pip install django".
Django was created inside C:\Python33\Lib\site-packages and not inside C:\users\username\projects\projB\Lib\site-packages.
Do I need to install pip inside my venv and use that to install Django?
You can specify in your virutalenv wich python version you whant:
$ virtualenv -p <PATH TO PYTHON VERSION> my_virtualenv
Then:
$ source my_virtualenv/bin/activate
$ pip install Django==1.5.2
This will install the good version of django in your virtualenv according to your python version.
Thanks to virtualanv, you will be able to save/freeze and install your environement on another machine:
$ pip freeze > requirement.txt
$ pip install -r requirement.txt
You will see in the requirement.txt file the django dependency.
Pip should be installed when you create the virtual environment. Don't change directory into C:\Python33\Scripts before running pip. It looks like that means you use the base install's pip instead of your virtual environment's pip.
You should be able to run pip from any other directory. However I'm not familiar with python on Windows, so I'm not certain that pip is added to the path when you activate the environment. If that doesn't work, you'll have to change directory into the bin directory of your virtual environment, then run pip.
What happened to me was that I was trying to install django from outside the environment directory/folder.
So make sure you are inside the environment directory and then use pip install django