I am trying to build a C++ program that embeds the python interpreter using pybind11. I am using Visual Studio 2019 on Windows with a C++ project (not CMake).
I want to use the packages that are inside a virtual conda environment (Anaconda3/envs/pytorchenv) rather than the root environment. The problem that I can't seem to get past is that the program uses the python installation in the Anaconda root environment no matter what I do.
Even if I "conda activate" the virtual environment in an Anaconda prompt before launching the program - it still uses the root environment. (I'm not sure if "conda activate" is supposed to modify PATH, but when I check my system environment variables, it doesn't change them).
I'm guessing there is something I can set in my Visual Studio project settings to indicate that I want pybind11 to use the virtual environment instead of the conda base path. Any help would be greatly appreciated. Thanks!
Related
can anyone help me understand using conda environment with visual studio code? I had activate the virtual environment (imageprocessing) with this:
conda activate imageprocessing
and the terminal seem to have been on virtual environment, so there's look like no problem with the PATH, it looks like this.
(imageprocessing) ../users/[project_folder_somewhere]
But when I open visual studio code and activate the kernel used for opening Notebooks there, exactly with the python from imageprocessing virtual environment, I keep needed to install the previously forged library, for example, Pillow. Which part that doesn't work out? Did I install Pillow package redundantly if I keep doing this? Does visual code doesn't integrated that well with conda even though it has been connected through the path? I used this feature for opening .ipynb files on Visual Studio Code because browser-based Jupyter Notebooks are too slow and messy directory than if using this (or so I thought?).
In VS Code, when we use different python environments, the locations where the modules are installed are different. Therefore, we need to be clear which python environment we are currently using. (We could check it with the command "python --version" in the VS Code terminal.)
When we use the conda environment, it comes with python, so we can use "pip" to install modules, or "conda" to install modules. The modules it installs are stored in: "...\anaconda3\envs\conda-name\lib\site-packages".
The command "pip show pillow" checks the installation position of the module:
In addition, after the installation is complete, it still shows that the module cannot be found. I noticed that there is a problem with the file name here. We need to rename "PIL" to "pillow", or use "import PIL"
Reference: conda-environment in VS Code.
Add:
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.
I want to link pycharm to my custom python environment called "tensorflow"
To do so I installed Miniconda3 on a windows 10 machine, created the environment and installed some packages there.
In my command prompt I can ofcourse activate the environment and see the packages installed with pip list.
Now I want to link this environment to pycharm, and for this I need the python interpreter and its location.
Having googled this is supposed to be in
C:\Users\foo\Miniconda3\envs\tensorflow\bin\
In my case however the folder is empty besides .nonadmin file and conda-meta map which also dont include an interpreter.
When I execute a python file that tells me the interpreter location from command prompt with the tensorflow interpreter it tells me the base interpreter is used.
C:\Users\foo\Miniconda3\python.exe
This seems wrong, and linking pycharm to this interpreter does not give me the right interpreter as the needed packages are not installed there.
I tried creating another environment to see if the same would happen, again an almost empty directory with no python interpreter there for me to link to.
How can I link my Tensorflow environment to pycharm?
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?
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: