How to run pipenv python as emacs Python shell

Viewed 1994

I use python-mode.el and have just discovered Pipenv. I can start Python within a project environment from a terminal by first changing to the project directory and entering "pipenv run python". But python-mode wants to execute a process, not a command string.

I tried creating a shell script like this:

#!/bin/bash
cd ~/myprojectdir
pipenv run python

but got this complaint

Warning: the environment variable LANG is not set!
We recommend setting this in ~/.profile (or equivalent) for proper expected behavior.

This variable is set in my terminal environment: how do i ensure it's set for pipenv? But the bigger question is, how do i run this pipenv virtual environment python inside emacs to get a buffer with a Python process?

2 Answers

Looks like i have to explicitly source my .bashrc file (or equivalent). Changing the contents of my runpipenv.sh script to this

#!/bin/bash
source ~/.bashrc
cd ~/myprojectdir
pipenv run python

(where my .bashrc file sets LANG) and then calling

(setq py-shell-name "runpipenv.sh")

in Emacs seems to work.

Related