SeanB
SeanB

Reputation: 950

How to run pipenv python as emacs Python shell

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?

Upvotes: 3

Views: 2355

Answers (3)

unifreak
unifreak

Reputation: 817

I'm using Emacs version 29, it's pretty straight forward:

Customize these two variables:

  • python-shell-interpreter. NOTE, I have to use absolute path to make Emacs find the executable, for me, the value is /usr/bin/pipenv.
  • python-shell-interpreter-args. My value is run python.

Upvotes: 0

user658587
user658587

Reputation:

pipenv.el helps here, by setting the appropriate variables and providing a porcelain around Pipenv inside Emacs.

Upvotes: 1

SeanB
SeanB

Reputation: 950

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.

Upvotes: 0

Related Questions