Quick Homebrew + miniconda python environment specification and REPL kernel creation: guide + scripts #19702
CEBangu
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Having a hard time getting Zed to find the right conda environment? Have (mini)conda installed with homebrew? Want a quick way of telling Zed which conda env to use, and to create a REPL kernel for a new env? Hopefully these scripts can help.
In order for Zed to use the right conda environment, you need to specify it in a pyrightconfig.json file in your root directory. This is tedious and cumbersome given you need to do this for every new project (and sometimes switch mid project). Script 1 deals with this. Moreover, REPL is great, but you need to initialize a new kernel for every environment. Script 2 deals with this. NB! What follows is written for a Zsh shell.
1. make_pyrightconfig.sh
This script creates a pyrightconfig.json in your current directory. It takes one argument which is the name of the environment you want to use in this directory. You will need to specify the path, which can be found using the command:
conda env list
, and taking the output before the /env name.In the terminal, in a nice directory (perhaps home), run
nano make_pyrightconfig.sh
. Then paste the following code:Where the path passed to venvPath is the one given by the
conda env list
command as specified above.To make this work, it must be an executable. So after saving the file, run:
chmod +x make_pyrightconfig.sh
Afterwards, running
./make_pyrightconfig.sh my_env
in the terminal will make this file in your current directory, specifying me_env as the conda env to use. Here, and throughout, my_env should be replaced with whatever your environment name is.To make this process even better, you can add an alias.
Run
nano ~/.zshrc
then, somewhere in there add:
alias convenient_alias_name="~/path/to/your/make_pyrightconfig.sh"
, where 'convenient_alias_name' is the string you want to assign the script command to. Then save the file, and apply the changes by runningsource ~/.zshrc
FWIW mine is 'mpc', so when I run
mpc env_name
in my terminal, it creates the pyrightconfig.json file that points Zed to the env_name environment.NB! you can use this same command to change the environment in the pyrightconfig - it will just overwrite the file.
2. create_kernel.sh
This script takes the env_name you want to create the REPL kernel for and installs the packages required via conda. The idea is the same. First make the create_kernel.sh in a nice directory, and paste
then
chmod +x create_kernel.sh
and./create_kernel my_env
will create the REPL kernel for my_env.The alias trick also works for this. You need to follow all the steps, including the application command.
3. Possible failure points
conda env list
should provide guidance here.If there is another way to do this, please leave it in the comments. The other way I've found is to manually create the pyrightconfig file and there is no way I am doing that. And apologies if this solution has already been implemented in a different post - I couldn't find it.
Also, this was written by a novice for novices. I appreciate this might be trivial, but compared to VScode this was a real pain...
Beta Was this translation helpful? Give feedback.
All reactions