how to apt install only in one environment? or is there work around? - pip

I use conda becouse it allow me to experminent with diferent version, but some time there are package only in apt or pip. so if i use apt from inside the env will it effect others or modifie the base env.
let sey install h5py for Python:
conda activate -n test sudo apt-get install libhdf5-dev sudo pip install h5py
I am trying to understand. becouse if i try to install from inside the env and it moidifie the other env, it will be a problem for me.

apt is an OS-level package manager for Debian and derivatives (Ubuntu). It installs packages globally, into the OS. It knows nothing about Python virtual environments.
If you want to install OS packages temporary, do experiments and then cleanup — use deeper virtualisation. Use virtual machines (qemu + Debian-in-Debian, VirtualBox + Ubuntu inside it) or containers (Docker, LXC, LXD, SystemD containers, whatever).

Related

pip install -r requirement.txt on virtualenv doesn't install locally but globally, even after activation

I tried to install all dependencies in my requirements.txt (a bunch of packages list).
What I did:
created virtual env virtualenv my_env
activated the new virtual env, I'm able to see my virtual env before the prompt (my_env) $
ran pip install -r requirements.txt
All packages got installed, but when checking with pip freeze I have nothing. Tried to deactivate the virtual env, and made pip freeze again, here I have all installed.
I'm a bit confused because, I'm very sure my virtual env was activated, and I have the right pip path when doing which pip inside it (/home/virtual_env/my_env/bin/pip). Plus, I tried to install one by one the dependency, and they got installed right inside the virtual env & displayable with pip freeze
I cannot do all of them one by one, and I need to reproduce the installation somewhere. Could someone helps on this?
Still no clean solution for this so far, but what would work is to copy-edit (search & replace the return character in the requirements.pip to && pip install. Meaning, edit it from this format
package1==vX.Y
package2==vU.V
...
into this
package1==vX.Y && pip install package2==vU.V ...
Add pip install at the beginning then make a copy to all for install command like
pip install package1==vX.Y && pip install package2==vU.V ...

installing packages to Mac desktop after using conda virtual environment

A few weeks ago I started using a virtual environment in anaconda to code. I did download a bunch of packages into that environment.
For some reason, now when I use pip to install packages, it installs directly into the virtual environment and not onto my desktop python.
When running sudo pip install --upgrade pip, it comes up with the following statement:
"Requirement already up-to-date: pip in /anaconda3/lib/python3.5/site-packages (18.1)"
Which if not obvious, is my virtual environment. This is the same when I try install other packages. (depending on whether the packages are up to date)
Thanks in advance

How do I install pip modules on google compute engine?

I am trying to run some python script using ssh to log into the google compute engine but all the installed pip modules are not found as I do not have permission to the .cache/pip folder in my user is there a correct way to do this?
You should be running this with the root user.
Also, if you need pip inside your GCP Instance, you can use the following commands:
sudo curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
sudo python get-pip.py
[Source]
Use:
sudo apt-get install python3-pip
sudo runs this command as an administrator
apt-get is the standard package manager used on Debian Linux distributions
python3-pip is the package name for pip3
Once installed, you can install PIP modules with:
pip3 install MODULE_NAME
for example:
pip3 install tensorflow
I'm not entirely sure there is one correct way to do this, but an easy way would be to use the conda python package manager.
The lighter version of it is miniconda. You can get a minimal python installation with pip preinstalled, and virtual environments capability if you need. Assuming you are running on linux and want python 3, you'll have to run
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
and then install conda with
bash Miniconda3-latest-Linux-x86_64.sh
At the end of this process you should have a minimal python installation (that includes pip) and you'll be able to install packages with pip as you are used to.
You might want to install some basic libraries first -
sudo apt-get install bzip2 libxml2-dev
Then install miniconda as given by #teoguso and restart your shell
source ~/.bashrc
You can then use conda or pip to install your packages

Dependency issue with conda, pip and virtualenv

I am using conda(anaconda 2). Before installing anaconda, my Ubuntu16.04 already had pip installed. I recently installed virtualenv using pip install virtualenv. I did the following steps while trying to install coala in my virtual environment.
Create a new virtual environment using virtualenv venv
Activate environment using source activate path/to/activate
Clone the coala repository.
Run pip3 install -e . while inside the repository
After all this, I get the following error from coala:
There is a conflict in the version of a dependency you have installed and the requirements of coala. This may be resolved by creating a separate virtual environment for coala or running `pip install "yapf~=0.14.0"`. Be aware that the latter solution might break other python packages that depend on the currently installed version.
I am already in a virtualenv, so I tried installing yapf as per the command: pip install "yapf~=0.14.0". After that, when I check my pip list, it still showed yapf (0.15.2), To solve this, I did:
pip uninstall yapf
pip install "yapf~=0.14.0"
Now when I check my pip list, I get the desired results. BUT, the error is still there. It still shows the same dependency error. I am unable to understand what is happening? Which pip is installing what and where, what is conda doing behind the scenes, how is virtualenv behaving with conda, and the most important, why this error and how to resolve it?
first create a virtualenv pertaining to python3.x
template
virtualenv -p {location of python3 version } {name of virtualenv folder}
like this
virtualenv -p /usr/local/bin/python3 venv
then activate it
source venv/bin/activate
then run
pip install {library you want to use}
pip install "yapf~=0.14.0"
This should install yapf into the venv folder.
try that let us know.
Answering my own question, what I found out was that conda and virtualenv do not go hand in hand. condas has the ability to create it's own virtual environment, and if using condas, we must create a conda virtual environment(See this answer).
What I did was uninstalled conda and make a virtual environment using virtualenv. What I could have done as well is uninstall virtualenv and create condas environment and work in that.

Installing Python Package to Conda Env Without Using Conda

I have a fresh Anaconda environment in which I would like to install the latest release of mysql-connector-python (v2.1.3). I'm on a CentOS6 system. The problem is, the newest Conda-hosted package is 2.0.3 and because the connector is not currently hosted on PyPI, it cannot be installed via Pip. (Pip's --allow-external option has been deprecated.)
I know that I can easily install the package via yum install, but I believe that will install it outside of the Conda environment.
Is there any way, using yum or otherwise, to isolate this package solely to this particular Conda environment?
Turns out this is surprisingly simple. Just download the source for the Python package that is not available on PyPI and pip install at the source directory. Just remember to have the Conda environment you want to install to active and Pip will correctly isolate the install to env scope.
I was unaware of Pip's install from local options, so big thanks to the folks on the Anaconda mailing list for their help with this.

Resources