pypa / pipenv

Python Development Workflow for Humans.
https://pipenv.pypa.io
MIT License
24.81k stars 1.87k forks source link

Help request: Using packages from both Pipenv & Conda #4897

Closed boonware closed 2 years ago

boonware commented 2 years ago

I am attempting to use packages installed by both Pipenv and Conda. Since Conda does not support "dev dependencies" I am using Pipenv to install packages such as Pytest. To run the tests I invoke the following:

pipenv install --dev
pipenv --python=$(conda run which python) --site-packages run pytest test

My Pipfile is:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[dev-packages]
pytest = '6.2.3'

I receive the following error:

Error: the command pytest could not be found within PATH or Pipfile's [scripts].

Am I doing something wrong? With the command above I assumed that both packages installed by Pipenv and those in the Conda environment would be available.

Pipenv version: 2021.11.23

matteius commented 2 years ago

@boonware I think I figured this one out. You should only pass --site-packages and --python the first time you run the pipenv to setup your virtualenv. Try this:

pipenv --rm
pipenv --python=$(conda run which python) --site-packages
pipenv run pytest test

As an example, since I don't have conda, I did this using my system python and first installed celery at the system level. Then see:

mdavis@matt-VirtualBox:~/shared-projects/pipenv-4897$ pipenv --python=$(which python) --site-packages 

Creating a virtualenv for this project...

Pipfile: /home/mdavis/shared-projects/pipenv-4897/Pipfile

Using /usr/bin/python (3.9.7) to create virtualenv...

Making site-packages available...

⠼ Creating virtual environment...created virtual environment CPython3.9.7.final.0-64 in 183ms

  creator CPython3Posix(dest=/home/mdavis/.virtualenvs/pipenv-4897-saECgZo0, clear=False, no_vcs_ignore=False, global=True)

  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/mdavis/.local/share/virtualenv)

    added seed packages: pip==21.3.1, setuptools==59.2.0, wheel==0.37.0

  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator

✔ Successfully created virtual environment! 

Virtualenv location: /home/mdavis/.virtualenvs/pipenv-4897-saECgZo0

mdavis@matt-VirtualBox:~/shared-projects/pipenv-4897$ pipenv install --dev

Installing dependencies from Pipfile.lock (c49525)...

  🎅   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 8/8 — 00:00:08

To activate this project's virtualenv, run pipenv shell.

Alternatively, run a command inside the virtualenv with pipenv run.

mdavis@matt-VirtualBox:~/shared-projects/pipenv-4897$ pipenv run pytest

============================================================= test session starts ==============================================================

platform linux -- Python 3.9.7, pytest-6.2.5, py-1.11.0, pluggy-1.0.0

rootdir: /home/mdavis/shared-projects/pipenv-4897

collected 0 items                                                                                                                              

============================================================ no tests ran in 0.01s =============================================================

mdavis@matt-VirtualBox:~/shared-projects/pipenv-4897$ pipenv run celery

Usage: celery [OPTIONS] COMMAND [ARGS]...

  Celery command entrypoint.

Options:

  -A, --app APPLICATION

  -b, --broker TEXT

  --result-backend TEXT

  --loader TEXT

  --config TEXT

  --workdir PATH

  -C, --no-color

  -q, --quiet

  --version

  --help                 Show this message and exit.

Commands:

  amqp     AMQP Administration Shell.

  beat     Start the beat periodic task scheduler.

  call     Call a task by name.

  control  Workers remote control.

  events   Event-stream utilities.

  flower   Web based tool for monitoring and administrating Celery clusters.

  graph    The ``celery graph`` command.

  inspect  Inspect the worker at runtime.

  list     Get info from broker.

  logtool  The ``celery logtool`` command.

  migrate  Migrate tasks from one broker to another.

  multi    Start multiple worker instances.

  purge    Erase all messages from all known task queues.

  report   Shows information useful to include in bug-reports.

  result   Print the return value for a given task id.

  shell    Start shell session with convenient access to celery symbols.

  status   Show list of workers that are online.

  upgrade  Perform upgrade between versions.

  worker   Start worker instance.