Setting up Emacs Elpy with Poetry - emacs

How can I configure Elpy to use dev dependencies like Black, Jedi, and flake8 that are installed in a Poetry project virtual environment rather than those that are installed systemwide?

Use the poetry.el Emacs package with poetry-tracking-mode enabled by add-hooking it to elpy-mode-hook. Elpy will automatically detect the Poetry virtual environment and check for those dev tools in that environment.
Jan 2021 update: I've since stopped using Elpy and switched to lsp-mode and lsp-python-ms - it's a far better development experience. The only caveat is that it can only discover virtualenvs local to the project, so Poetry has to be configured to create venvs locally (poetry config virtualenvs.in-project true).

If you use emacs -nw, then another option is
Install virtualenvwrapper in poetry project. That is run poetry add -D virtualenvwrapper.
Install elpy dependencies you need. M-x elpy-config' to find dependencies. So poetry add -D jedi rope autopep8 yapf black flake8`. This can also be done when elpy prompts you, but then it will probably install as a normal dependency and not just dev dependency.
Add (setq elpy-rpc-virtualenv-path 'current) so that elpy uses the poetry virtual env for Virtualenv, Interactive Python, RPC virtual env.
Launch emacs through poetry poetry run emacs -nw
You need to do this for each poetry project. There should be way to install some of these globally in pyenv and have poetry and the project virtual env pick it up. However, doing it for each project keeps dependencies isolated, even for dev stuff.

Related

conda installed emacs suddenly not working after upgrading ubuntu 20.04 LTS to 22.04.1 LTS

I just recently upgraded to ubuntu 22.04.1 LTS (from ubuntu 20.04 LTS). Before, my conda environment for emacs worked fantastically.
My conda environment I created - and retried creating using:
conda create --name emacs
conda activate emacs
conda install -c conda-forge emacs
emacs &
Output:
emacs: symbol lookup error: emacs: undefined symbol: malloc_get_state, version GLIBC_2.2.5
And emacs doesn't even start.
Does somebody know what is going on?
"Solution":
My "Solution" so far was just to install emacs globally and use it.
Oh, I see in the GLIBC 2.25
https://elixir.bootlin.com/glibc/glibc-2.25/source/NEWS
* The malloc_get_state and malloc_set_state functions have been removed.
Already-existing binaries that dynamically link to these functions will
get a hidden implementation in which malloc_get_state is a stub. As far
as we know, these functions are used only by GNU Emacs and this change
will not adversely affect already-built Emacs executables. Any undumped
Emacs executables, which normally exist only during an Emacs build, should
be rebuilt by re-running “./configure; make” in the Emacs build tree.

How can I make auto-complete work with ELPY in emacs?

I am trying to configure my emacs for python programming. Elpy auto-complete suggestion is not working at all in all instances. Any suggestions?
Here is my elpy-config...
Elpy Configuration
Emacs.............: 26.3
Elpy..............: 1.31.0
Virtualenv........: None
Interactive Python: python 3.7.4 (/Users/mdmorshed/.pyenv/shims/python)
RPC virtualenv....: rpc-venv (/Users/mdmorshed/.emacs.d/elpy/rpc-venv)
Python...........: python 3.7.4 (/Users/mdmorshed/.emacs.d/elpy/rpc-venv/bin/python)
Jedi.............: 0.15.1
Rope.............: 0.14.0
Autopep8.........: 1.4.4
Yapf.............: 0.28.0
Black............: 19.3b0
Syntax checker....: flake8 (/usr/local/bin/flake8)
You have not activated a virtual env. While Elpy supports this, it is
often a good idea to work inside a virtual env. You can use M-x
pyvenv-activate or M-x pyvenv-workon to activate a virtual env.
The directory ~/.local/bin/ is not in your PATH. As there is no active
virtualenv, installing Python packages locally will place executables
in that directory, so Emacs won't find them. If you are missing some
commands, do add this directory to your PATH -- and then do
`elpy-rpc-restart'.
Elpy is suppose to provide auto-completion out-of-the-box. As your elpy-config seems fine, I would suggest reporting the issue in Elpy repository here.

How to Activate ENV Created By Virtualenv Having Conda Installed

So I have conda installed first, then Virtualenv, on Windows 10.
Now both tools use "activate env" to activate envs created. I found conda's activate function overrides virtualenv's (could be vice versa in theory).
I'd like to find out how to choose which activate to use. Or at least, how to activate env created by virtualenv. Thanks!

How to use ipython without installing in every virtualenv?

Background
I use Anaconda's IPython on my mac and it's a great tool for data exploration and debugging. However, when I wish to use IPython for my programs that require virtualenv (e.g. a Django web app), I don't want to have to reinstall IPython every time.
Question
Is there a way to use my local IPython while also using the rest of my virtualenv packages? (i.e. just make IPython the exception to virtualenv packages so that the local IPython setup is available no matter what) If so, how would you do this on a mac? My guess is that it would be some nifty .bash_profile changes, but my limited knowledge with it hasn't been fruitful. Thanks.
Example Usage
Right now if I'm debugging a program, I'd use the following:
import pdb
pdb.set_trace() # insert this to pause program and explore at command line
This would bring it to the command line (that I wish was IPython)
If you have a module in your local Python and not in the virtualenv, it will still be available in the virtualenv. Unless you shadow it with another virtualenv version. Did you try to launch your local IPython from a running virtualenv that didn't have an IPython? It should work.
Will, I assume you are using Anaconda's "conda" package manager? (Which combines the features of pip and virtualenv). If so you should be aware that many parts of it does not work completely like the tools it is replacing. E.g. if you are using conda create -n myenv to create your virtual environment, this is different from the "normal" virtualenv in a number of ways. In particular, there is no "global/default" packages: Even the default installation is essentially an environment ("root") like all other environments.
To obtain the usual virtualenv behavior, you can create your environments by cloning the root environment: conda create -n myenv --clone root. However, unlike for regular virtualenv, if you make changes to the default installation (the "root" environment in conda) these changes are not reflected in the environments that were created by cloning the root environment.
An alternative to cloning the root is to keep an updated list of "default packages" that you want to be available in new environments. This is managed by the create_default_packages option in the condarc file.
In summary: Don't treat your conda environments like regular python virtualenvs - even though they appear deceptively similar in many regards. Hopefully at some point the two implementations will converge.

Can't make emacs to load the correct virtualenv

I wan't to compile python project in emacs. This project is running in a virtualenvwrapper environment. So i found a emacs plugin called virtualenvwrapper and use M-x work-on to choose virtualenv. After i have done this, the python interpreter and shell has been set to the correct python env, but when i compile emacs with M-x compile, it still can't found all the packages installed in python env.
I found this issue may be caused by zsh. After i change the default shell to bash in terminal. virtualenv works fine. Is it a bug of zsh or i haven't configured zsh with the right way.