Pipenv: Unable to run single python script by pipenv during docker build

Created on 2 Feb 2018  路  3Comments  路  Source: pypa/pipenv

Using pipenv run directory/somescript.py causees pipenv to fail, because it looks for directory/somescript.py in PATH

Describe your environment
  1. OS Type Ubuntu
  2. Python version: $ python -V python 3.6
  3. Pipenv version: $ pipenv --version master
Expected result

pipenv runs script using created virtualn environment

Actual result

Step 26/29 : RUN ls $PROJECT_PATH | grep setup.py
---> Running in 7811236ec5ee
setup.py
Removing intermediate container 7811236ec5ee
---> ba280fab02c3
Step 27/29 : RUN pipenv run $PROJECT_PATH/setup.py develop
---> Running in b48df28fbe12
Error: the command /opt/project/setup.py could not be found within PATH.

Steps to replicate

extract from dockerfile:
RUN ls $PROJECT_PATH | grep setup.py
RUN pipenv run $PROJECT_PATH/setup.py develop

Most helpful comment

@jacekjab you can鈥檛 run pipenv shell inside of Docker due to it not supporting sub shells as noted in the stacktrace. pipenv run is intended for scripts/applications installed on the path with a shebang specifying how they should be used.

In your case I believe what you鈥檙e looking for is pipenv run python somescript.py or add a shebang to the top of the script.

All 3 comments

And changing Dockerfile to:

ENV SHELL=/bin/bash
RUN pipenv shell -c "$PROJECT_PATH/setup.py develop; exit $?"

results in

Spawning environment shell (/bin/bash). Use 'exit' to leave.
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 11, in <module>
    load_entry_point('pipenv==9.0.3', 'console_scripts', 'pipenv')()
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/cli.py", line 2204, in shell
    do_shell(three=three, python=python, fancy=fancy, shell_args=shell_args)
  File "/usr/local/lib/python3.6/site-packages/pipenv/cli.py", line 2167, in do_shell
    c.interact(escape_character=None)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/pexpect/pty_spawn.py", line 744, in interact
    mode = tty.tcgetattr(self.STDIN_FILENO)
termios.error: (25, 'Inappropriate ioctl for device')

I guess you can probably achieve the same with: pipenv run python -c "import this" (just replace import this with your logic).

@jacekjab you can鈥檛 run pipenv shell inside of Docker due to it not supporting sub shells as noted in the stacktrace. pipenv run is intended for scripts/applications installed on the path with a shebang specifying how they should be used.

In your case I believe what you鈥檙e looking for is pipenv run python somescript.py or add a shebang to the top of the script.

Was this page helpful?
0 / 5 - 0 ratings