Can't make emacs to load the correct virtualenv - emacs

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.

Related

Wrong Python interpreter being used by VS Code

I am on Ubuntu 20.04 and have both Python2 and Python3 installed natively. I have also installed Python through miniforge, a variant of miniconda. In VSCode I have both the MS Python extension and Pylance installed.
I use the miniforge python for my coding. This works perfectly fine in PyCharm.
However in VSCode, when I try to execute the same file I get errors. After investigating it seems that VSCode is picking native Python2 - even though I have the miniforge Python selected. In this picture it can be seen that the status bar at the bottom states Python interpreter selected is Python3. But the output window shows that the python interpreter is Python2.
A more confusing thing is when I use VSCode for Jupyter notebook files then it picks up the interpreter correctly and I have no issues.
I have checked both User and Workspace settings, and they all point to Python3. How can I fix this for standard .py files?
I prefer VSCode to PyCharm, but will need to use PyCharm till this is resolved.
It seems that your system console cannot see python3. You need to put the python3 in the PATH variable, before python2. Like:
PATH=path/to/python3:path/to/python2:$PATH
Also, make sure that the environment containing python3 is activated before command prompt appears. It can be done in bash_profile by adding a line like
conda activate my_env_with_python3
Try changing the settings "Python:Python path", "Python:default interpreter path" and "Python:conda path" also.
I have just bumped into something similar. The Run code option resulted in the file being run with the default interpreter instead of the venv-based one with necessary packages installed.
The fix was simply to use "Run python file" instead:
The run-code behavior must be customizable, something is mentioned e.g. here: Run Code vs Run Python File in Terminal for VSCODE but I didn't bother.

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.

Using conda environment in IPython interactive shell

I am trying to use the interactive shell of IPython within my conda env and am having issues.
The steps I take are:
source activate myenv
conda install ipython
ipython
When I am in ipython interactive shell, it calls python from the anaconda root bin. (~/anaconda2/bin')
Is there anything I can do to change the python path to ~/anaconda2/envs/myenv/bin and import packages from myenv?
I see few solutions to making env work in jupyter when I search the web, but no answer on making it work on the interactive shell.
This is likely due to your $PATH variable being messed up.
THe easiest way to make sure you get IPython from within an env is to use $ python -m IPython <rest of the options> to start IPython. This works for many of the Python installable application; like pytest, pip and other.

elpy with Winpython: how to configure?

I'm trying to setup elpy for emacs on my windows system, on which I'm using Winpython 3.4.3.
I have installed all the dependencies such as rope, flake8, etc... using pip. When I type M-x elpy-config in emacs, I get "Neither easy_install nor pip found".
If I run (executable-find "python") then I get the correct path to my Winpython installation.
What might be the problem?
On Windows 7 with Emacs 24.5 and Python 2.7 it worked for me to include the actual directory containing pip (Scripts) in the exec-path; using M-x customize-variable exec-path. Apparently, including just the directory of the python executable was not enough.

Unable to start ipython with .pythonrc using virtualenv

I want to be able to start an ipython session with it importing some modules. On Windows this would be simple - I had a global installation of ipython and I used .pythonrc I think it was.
However, in Ubuntu 13 I have ipython installed in a virtualenv (but not installed globally).
In my .bashrc is:
alias ipy="python -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'"
I am wondering if it's possible to run similar startup commands in ipython. Or if that's not possible with my current setup - then what is the best way to achieve what I want in Ubuntu.
Hopefully some combination of PYTHONSTARTUP or IPYTHONDIR environment variables in your .bashrc can accomplish what you want.