0

I'm an amateur when it comes to both conda and venvs in general (as well as s/o), so I was hoping someone could give me an explanation of how to deal with these 3 paths.

Conda/Global Example

I'm within a conda environment and trying to install tensorrt and its python bindings. It's available as a debian package, so I 'apt-get' it. I assume this will install it globally, and my conda venv will be able to 'see' it, but this is not the case. It's only available once a deactivate my environment. How do I enable this package to be used from my conda env?

Conda/Sudo Example

I'm within a conda env, and wish to install a python package not available as a debian package, but rather a setup.py. I wish to install it globally (available to all environments, virtual and non) and run its setup.py with 'sudo python'. This resolves to a different path, not visible from within my virtual environment or local path. The exact opposite of the goal. How do I make this package visible to my conda venv?

Any help is appreciated.

Xenos
  • 3
  • 1
  • _I wish to install it globally (available to all environments, virtual and non) and run its setup.py with 'sudo python'._ Why? You wrote in a comment _I agree with the messed up development environment, that's why I'm trying to sort it out now_, but isn't this kind of thing what messes up the environment in the first place? – AMC Mar 30 '20 at 23:32
  • Yeah you make a good point. I guess me confusing global installs as the exact opposite of virtual environments is the problem. Using the python within the conda on the setup.py seems like the best way to maintain separation. – Xenos Apr 01 '20 at 12:00

1 Answers1

0

You are mixing a lot of packaging management systems together (apt, conda, pip). Furthermore your questions defeats the purpose of using virtual environments. You should only use sudo when installing Python packages when you know exactly what you are doing.

I am going to give you some guideline that leads to a solution but I recommend you to sort out your development environment first because it will just lead to more headache. Decide on something and stick to it.
Maybe you shouldn't use a virtual environment if you don't want the benefits of using a virtual environment.


I'm going to write python3. For you it may be called py, py3 or python. You can get the PATH of your python3 command with which python3 on Linux and where python3 on Windows.

When you install packages. They are put in one of the folders listed at python3 -m site. You can activate your virtual environment and see that the folders are different.

You will see that your current working directory is automatically added. You can see that each user has their own site-packages folder and that there is some common folder /usr/lib/python... which is part of your Python interpreter. They contain basic functionalities and usually you don't install custom packages into there.

How can you install the Python modules to a custom path?
I'm linking another StackOverflow question since it varies. Install a Python package into a different directory using pip?
Please do your own research with Conda.

How can I make my program use the Python modules defined in the new path?
Use PYTHONPATH.
When you execute python it will look up all the modules listed in the folders at python -m site. You can add another folder for example with: PYTHONPATH=/home/ python -m site


I omitted a lot of information and this is not a wiki or similar. This is merely an answer that leads to a solution but it's not a pretty one.

Tin Nguyen
  • 5,250
  • 1
  • 12
  • 32
  • Thanks for help Tin. I agree with the messed up development environment, that's why I'm trying to sort it out now. So a global package install completely removes the need for a venv, which makes sense now that I think about it. But what if a package is only available either via apt or a setup.py install? Should I symlink the resulting install into my specific virtual environment to maintain some separation? – Xenos Mar 25 '20 at 18:56