How to manage (ana)conda with pycharm 2016.3 in linux - python

I would like to use Anaconda and the newest Pycharm 2016.3 together. I would like to be able to manage packages in settings->interpreter. If this is not supported, I would like to know the workflow of using these two together. According to another SO question, Pycharm 5 used to have a 'Create conda env' in the interpreter settings, but this seems to be gone now. I have tried:
1) Manually creating a virtual environment with 'conda create --name project numpy' and I add the interpreter ('~/anaconda2/envs/bin/python', the location of python for my created virtual environment. However, pycharm doesn't allow me to add any packages through settings->interpreter. Running an 'import numpy' through the console shows errors that are pointing to /usr/bin/python, not my virtual env python, and an error 'ImportError: cannot import name multiarray'. I'm not sure what package to add using conda from the cli, and the pycharm frontend doesn't add packages
2) I've tried the same as 1) but with my global anaconda python as the interpeter ('~/anaconda2/bin/python') and it doesn't seem to be able to connect to the console.
3) Creating a virtual environment through pycharm directly.
I would like to remove my default pythons (/usr/bin/python2.7/3.5 from the list of interpreters in pycharm) for debugging purposes but it won't let me and it seems to be showing packages that my anaconda virtual env doens't have installed.
Is there a way to manage my VIRTUAL enviornment in Conda using pycharm? If not, what steps do I take to make these two play well together assuming I can't manage it through pycharm interepreters settings.

This is the normal steps that i follow when i use virutalenv with PyCharm
I normally work on ubuntu
First, i always create a separate environment for every project using the command virtualenv "environment_name" from the command line.
Activate the environment using the command - source environment_name/bin/activate in ubuntu.
Suppose if i want to start a django project, i create the project using the command django-admin startproject project_name
Open this project in pycharm.
go to settings-> interpreter in pycharm. choose "add local" interpreter from the settings. It will open a pop-up. Go to the directory of the environment you just created and select the correct python interpreter you want to use.
now if you want to install a new package, you can go to interpreter settings and add package from the pycharm or you can fire up the command line, activate the environment and run pip install package_name. Once the package is installed, it will also show in pycharm.
if you are using Windows OS, use powershell to execute the above commands. The only difference will be in activating the environment. In windows, to activate an env use environment_name/Scripts/activate
EDIT:
Same goes anaconda environments also, the easy way is to manage the environment from the terminal and pycharm will show the packages changes in the interpreter settings.

Here is what I have been doing and it works great. I create a virtual environment separately and when I create a new project in PyCharm, I point the interpreter to the python from the virtual environment. An example is shown in the picture below:

Related

How can I set up Python virtual environment in VScode so that it views locally-installed modules?

I have created a virtual environment via the command line
python3.11 -m venv .
source ./bin/activate
python -m pip install NAME_OF_MODULE
source deactivate
I can see the installed modules when I run pip freeze (prior to deactiving). So far so good.
Then I launch VSCode, open a file and using the command palette, I click Python: Select Interpreter. I then navigate in the bin folder of the virtual environment to the Python installation, which consists of a short-cut / alias pointing to a global Python installation.
When I do this, I cannot import Python modules located in the virtual environment, only those in the global environment. In other words, it appears to be selecting the global environment.
Do I need to set this up within VSCode (Python: Create Environment) ? If so, I can only get so far as the official instructions (https://code.visualstudio.com/docs/python/environments) do not cover installing packages within a virtual environment.
Thanks
I managed to do this in VSCode, by choosing the Create Environment command from the Command Palette. This created a .venv folder where the Python installation is contained. Then when I go to select the Python interpreter via the Command Palette, it automatically finds the local installation. Then, I installed packages by opening the command line WITHIN VSCode (no need to activate environment - it is already automatically activated).
So the trick is to create the environment WITHIN VSCode, not using the system shell.

How to Configure Poetry Environments in Pycharm With Windows + WSL2?

TL;DR: can't configure a Python Interpreter on PyCharm (Windows) using an existing Poetry environment in WSL. When trying to set the Poetry environment path under Add Python Interpreter > Poetry Environment > Existing Environment, the needed Python executable simply does not show. What am I doing wrong?
====================================================
Details:
I'm using PyCharm Pro 2021.3 on Windows 11, with Python running on WSL2 (Ubuntu 20.04). I am trying to add a python interpreter for an existing Poetry environment I created on WSL2, and it just does not seem to work.
PyCharm's current support of Poetry is via adopting this plugin. From what I could gather from the plugin's official documentation, in order to define an interpreter with an existing Poetry environment, I go to Python Interpreter > Add > Poetry Environment, choose Existing environment, and put in the path to that specific environment:
In order to find the path to that environment, I run "poetry env info", which gives a path in the following pattern:
\\wsl$\Ubuntu-20.04\home\$USER$\.cache\pypoetry\virtualenvs\my-pretty-project-<some-hash>-py3.8\
When running which python in the environment, I see the python executable is at:
\\wsl$\Ubuntu-20.04\home\$USER$\.cache\pypoetry\virtualenvs\my-pretty-project-<some-hash>-py3.8\bin\python
However - when I browse to that location in PyCharm, the Python file simple does not show. The bin directory appears as empty - as also described in this question. However - and similarly to what described in said question - if I try to redefine the default interpreter path for WSL to be the path to that Poetry environment, the Python executable is there and kicking:
(The solution described in the aforementioned question, sadly, does not work for my problem, as I am already using the patch to the Poetry environment).
What can I do to make this work?
Let me get this straight: You want PyCharm for Windows to execute Python binaries in WSL?
That cannot happen.
Binaries in WSL are "ELF" binaries which Windows cannot execute (outside WSL). If the virtualenv was created by poetry from within WSL, it will contain ELF Python binaries. And that is why PyCharm for Windows won't ever pick it up. Because ultimately PyCharm for Windows relies on Windows to execute the binaries, as long as you don't choose the WSL option.
Explicitly selecting the "WSL" option indicates to PyCharm that for this particular virtualenv you want PyCharm to invoke the binaries using WSL.
The solution is either to re-create the virtualenv in Windows, or just use the "WSL" option but you have to manage the poetry manually via WSL shell.

mambaforge, conda executable path is empty in pycharm interpreter(Linux mint 20)

I have installed conda environment using mambaforge to use snakemake. I have followed the instructions of Snakemake setup tutorial to install mambaforge. I have created the environment and created a .py file, but when I try to run it, it shows the plain code rather than compiling it. When I went to fix it and to add a Conda environment in my PyCharm interpreter it shows me the following error:
I tried to add the conda executable path by browsing to mambaforge/bin/conda but it still shows me the error.
I also tried to use which conda to find the right path, but rather than giving me a path the following is show, I have tried which conda in conda base environment as well as my setup environment, all it returns is the following:
I am sure that my conda environment is setup as conda --version command shows me the version I have installed.
the conda bin installed with mambaforge is at ~/mambaforge/condabin/conda
I'm not aware of mambaforge conda distribution, I'm using Anaconda / Miniconda distributions with an installed mamba module, so I could create a snakemake environment using terminal (i.e. from command line) and register as Python interpreter in PyCharm Settings as "Conda Environment | Existing environment" (see your first screenshot).
So I suggest you:
check whether "Existing environment" works for you, e.g. is able to find you conda environments (e.g base, or others).
You could set up Anaconda/Miniconda + mamba + configure PyCharm for using Snakemake with the help of my detailed guide that I use for my students' homework on snakemake.
P.S: I always run snakemake scripts using command line, e.g from terminal bundled into PyCharm, or just system terminal app or on remote server. I don't use PyCharm run configurations for that. As for PyCharm, I use it with SnakeCharm plugin to have a good snakemake & python code editing support

Using Conda Environment from PyCharm

I've looked at all the responses in the search and specifically Use Conda environment in pycharm without resolving my problem.
I'm on Win10 using the latest Anaconda and PyCharm for Python 3.6. The situation is that I've created a new environment using Conda which uses the Python version available in the base environment. Therefore, there is no python.exe in the newly created environment. In PyCharm, when I try to select the Conda environment, the dialog apparently does not see a Python there and refuses to set that as the environment.
In PyCharm, I create a new Project (pure Python) and set the location for the project in my PyCharmProjects directory. I then try to select existing interpreter and navigate to the appropriate Conda environment which I'm unable to select.
I'm not sure if there is something I don't understand or there is actually a problem here, but I'm getting a bit frustrated trying
to find the proper approach. Any help appreciated.
--Don
When you create the conda environment from cmd prompt do you explicitly tell it what python you want to use?
conda create --environmentName python=3.6
That should place a python.exe in your environment.

Activating conda environment without separate Python version in IDEs

I recently created a conda environment (in Ubuntu 16.04), which is working great from the command line. I can activate it with no problems, the packages are properly separated, etc.
However, because it is running the same version of Python as the Anaconda installation (Python 3.6.1), it has not created a separate interpreter. Within the /anaconda3/envs folder there are no other folders. This makes it difficult when I want to use editors (such as vscode and Pycharm) because they cannot find the path to some of the packages I have installed in the environment. I would love to start using the great debugging features in Pycharm but without a separate interpreter I have no idea where to even start. Is there a way to initialize the interpreter in the correct environment?
When I run conda info --envs, this is what I get:
# conda environments:
#
chatbot /home/bradley/.conda/envs/chatbot
tensorflow /home/bradley/.conda/envs/tensorflow
tf_testing /home/bradley/.conda/envs/tf_testing
root * /home/bradley/anaconda3
If I try to run the Python in these directories (a small executable script exists), it doesn't include all the packages. Should I maybe add an environment variable? If so, what would I write?

Categories

Resources