Force pip to install in system site-packages? - python

When I install packages with python 3 on ubuntu 16.04, they get installed to my local user ~/.local/lib/python3.5/site-packages. How do I force pip to install to the system-wide site packages?
I'm trying by using pip3 install <pkg>
Thanks.
This is NOT a duplicate of How to make my Python module available system wide on Linux? - because that is about creating your own module, not a a strange way that pip is working for a Pypi module. Not even close, actually, other than they both deal with modules.

Related

Python package installation via yum

What could be the difference of installing python packages via yum vs. via pipon Centos in terms of security? Is it even possible to install a python package only via yum?
yum can be used to install Python on CentOS.
pip is used to install Python libraries (packages). Not Python itself.
No "security" issue. But with yum you could overwrite your native Python installation, which can be a problem.
Instead of that, it is recommended to use virtualenv.

Should I manually install all my system wide packages after upgrading to Python 3?

I have some systemwide packages I've installed and I'm unclear whether I'm supposed to install another copy of them all for Python3 or if there is some way to 'point' Python3 at them. I'm on a Mac.
I still have Python 2.7.9 which has all the packages (most installed with either brew or pip and maybe one or two manually like pyqt). Do I basically have to redo the installation process for every single package again? Or is there some way to simply have Python3 'inherit' everything I've installed so far under 2.7.9?
Also, from what I understand, to install under Python3 with pip I would use pip3 install, is that correct? How would I do the same with ones installed with Homebrew? Is there a brew3 command? Or does Homebrew install to all versions of Python?
You do need to reinstall, but I would step away from systemwide installs in general and start using project-specific package installation.
Use pyenv for version switching and virtualenv for isolated environments.
pyvenv works rather well.
Install Python 3
python -m venv "my_virtual_env"
my_virtual_env\Scripts\activate
pip search lib
pip install ...
You will have to look up what the activate command is for osx. pip is the standard package manager now. You can search, install, and uninstall with pip. Pip is also moving towards wheels when installing packages. You probably don't have to worry about wheels too much though.

Python 3.3 and Installing PyOpenSSL on a Mac

I have python 3.3 working and can run some basic code (like print("Hello World")). Next I need so get PyOpenSSL set up. I've downloaded and unzipped the pyOpenSSL-master.zip from their github site, but I have no idea what to do with it next.
I moved the unzipped directory into /libs, cd into /libs/pyopenssl-master and did python setup.py install --user. But that failed with
/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
Other than the directory not existing, which I assume that the installer would create, the bigger problem is that it appears to be trying to write to the python 2.7 folder and I'm using 3.3.
If you can't tell, I'm pretty much out of my element. I've never installed a Python library before and I'm also not great with OSX installations. Can anyone help me get this set up? Thanks.
Here's how you can install pyOpenSSL on OS X (or just about any other platform):
Install pip
Install it using a package for your operating system. For example, if you use brew, brew install pip.
If there is no package for your operating system, download https://raw.github.com/pypa/pip/master/contrib/get-pip.py
Run it (probably as root, unfortunately): sudo python get-pip.py
Install virtualenv using pip - pip install --user virtualenv
Create a virtualenv to install pyOpenSSL into - virtualenv ~/Environments/pyOpenSSL-stuff
Activate the virtualenv - . ~/Environments/pyOpenSSL-stuff/bin/activate
Install pyOpenSSL with pip - pip install pyopenssl
At this point you have pyOpenSSL installed in a virtualenv. Any time you want to use pyOpenSSL you'll need to activate the virtualenv. I suggest that you actually create a virtualenv for each project of yours that you work on and install all of the necessary dependencies for each project into that project's virtualenv.
This does result in a lot of duplicate installations of packages. Unfortunately this seems to be the state of the art for Python package installation. Fortunately most Python packages are rather small.

How to Uninstall setuptools python

Hi recently i installed setup tools module and google app engine gives me errors . Is there a way to uninstall setuptool? can any one tell me step by step because i tried hard
The answer depends on how it was installed.
If it was installed using the ubuntu (debian) package manager, try:
sudo apt-get remove --purge python-setuptools
[updated]
If you installed manually, probably the setuptools final location will be something like (adjust for your environment/python version):
/usr/local/lib/python2.6/dist-packages
Just delete the setuptools stuff there.
Lame, I know, but it is your burden for not using the excellent package manager provided by ubuntu: stick to dpkg unless you need bleeding edge stuff. For other python modules installed by setuptools, it provides no "uninstall" feature (but pip does, that is why there is a lot of enthusiasm around virtualenv, pip and yolk).
[2017 update]
It is 2017 and installing Python modules changed a bit:
pip is now the preferred installer program. Starting with Python 3.4, it is included by default with the Python binary installers.
venv is the standard tool for creating virtual environments (semi-isolated Python environments that allow packages to be installed for use by a particular application, rather than being installed system wide), and has been part of Python since Python 3.3. Starting with Python 3.4, it defaults to installing pip into all created virtual environments.
virtualenv is a third party alternative (and predecessor) to venv and if not official it is still very popular because it allows virtual environments to be used on versions of Python prior to 3.4, which either don’t provide venv at all, or aren’t able to automatically install pip into created environments.
easy_install pip
pip uninstall pip setuptools
(pip and setuptools both use the same package formats, but pip has uninstall support. kinda hilarious that installing something is the easiest way to uninstall.)
I was having trouble with the method below because my pip wasn't up to date.
easy_install pip
pip uninstall pip setuptools
After upgrading pip like this:
sudo -H pip install --upgrade pip
I was able to successfully uninstall setuptools like so:
pip uninstall setuptools

Installing Python egg dependencies without apt-get

I've got a Python module which is distributed on PyPI, and therefore installable using easy_install. It depends on lxml, which in turn depends on libxslt1-dev. I'm unable to install libxslt1-dev with easy_install, so it doesn't work to put it in install_requires. Is there any way I can get setuptools to install it instead of resorting to apt-get?
setuptools can only install Python packages that in the package index you are using, either the default index of the one you specify with easy_install -i http://myindex.site/index.
Any non-Python dependencies have to be installed using the standard installation package for the platform (apt-get on Debian based Linux distros). libxml2 and libxslt fall into this category so you should install these in the standard way.
It's better use apt-get to install lxml (or the python packages that has c extensions) and then pull pure python package from pypi. Also I generally try to avoid using easy_install for top level install, I rather create a virtual env using virtualenv and then use easy_install created by virtualenv to keep my setups clean.
This strategy is working successfully for me for couple of production environments.

Categories