0

i want to have two version of a module, one version in pip(e.g:newer version) and the other(e.g: older version) in pipenv, but when i install a package using pipenv, it will also works with pip, i don't know how to create a different environment with pipenv in pycahrm IDE that the packages won't install in pip.

and also pycharm inform me this code every time i execute a command using pipenv:

Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPEN V_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.

how can i set pipenv_ignore_virtualenvs to 1?

is it even possible to use two different enviroment at one time?

  • 1
    What do you mean by two different environments at one time? Like activating two virtualenvs in the same terminal? You should be able to have two virtual environments and run them (activate them) in separate terminals. Each environment with a different module version – EDG956 May 17 '22 at 17:35
  • i told this based on editor apps. in editor we do it by change pip to pipenv in one terminal but is it the same with switch iterpreter in ides? – amirhossein May 17 '22 at 17:56
  • You need to create virtual environments. pipenv allows you to spawn a virtual environment with `pipenv shell` I believe. Then you can install dependencies to that virtual environment and have the other modules installed with pip. For that matter you don't even need to differentiate between pipenv or pip. – EDG956 May 18 '22 at 06:51
  • I'd recommend you read about python's `venv` module. pipenv and poetry have their own virtual environment managers, but understanding `venv` will be easier and to the same effect as using any of those two other – EDG956 May 18 '22 at 06:54
  • Basically you don't need pipenv for what you're trying to do, although it's a nice tool that also does it for you. You could have two different virtual environments and manage dependencies only with pip. – EDG956 May 18 '22 at 06:56
  • i understand what are you saying, but when i create a virtualenv with pipenv and install packages with pipenv the packages are also installed in pip and i must change interpreter to use different env. i wonder is it the same work that we do in editors or not? cause in editors we just change env in terminal(e.g: exit from shell environment and install newer package in pip). – amirhossein May 18 '22 at 08:33
  • I am pretty sure it doesn't depend on pip or pipenv, but on the value (or lack of existence thereof) of the environment variable PYTHONPATH. That's where python expects to find modules and stuff. – EDG956 May 18 '22 at 12:08
  • Sorry. More precisely it sets the `VIRTUAL_ENV` environment variable, which tells python it's in an environment variable and uses that as a reference to find modules (search for that in [the docs](https://docs.python.org/3/library/venv.html)) – EDG956 May 18 '22 at 12:16

1 Answers1

3

Basically, you can't, because it doesn't depend on pip (or pipenv or poetry) where the packages should be installed. Python will install packages wherever it's configured to do based on the values of sys.prefix or sys.prefix_exec, as explained here.

If you want to manage two different versions of a dependency, the one thing I can think of is having two separate virtual environments, each with its own dependencies. Then, you can switch between environments as you please. But you can't have two versions of the same package installed (unless you modify its source and install it locally as well) in the same environment, and definitely changing between pip or any dependency installation tool won't help you.

Here's a nice article that explains what happens when you activate a virtual environment and why it does not depend on pip where they are installed

EDG956
  • 797
  • 8
  • 23