I want use the python on wsl in pycharm
I refer to this article
https://www.jetbrains.com/help/pycharm/using-wsl-as-a-remote-interpreter.html#prereq
pycharm can connect wsl by ssh,but Failed
https://i.stack.imgur.com/26ni1.png
It seems that the interpreter you are trying to use is not installed in your WSL, or you are pointing the wrong place. Make sure it exists, if not try to use /usr/bin/python as the interpreter.
I use miniconda and have python 3.6 installed on /home/USERNAME/miniconda/. In pycharm, I point the interpreter to /home/USERNAME/miniconda/bin/python3.6.
For different conda envs, point the interpreter to their respective python
Related
I am new to python and I guess pyCharm is the most preferred IDE for python but I want to stick to vscode if possible. I have the python extension installed in vscode and autocomplete works fine for default python packages but for external packages like pillow or PyPDF2, its not working.
I created a virtual environment where I installed the above 2 packages using pip and even checked if the packages are installed using pip freeze.
Pip freeze is showing:
Pillow==9.0.1
PyPDF2==1.26.0
Below is my project structure. I need to import PyPDF2 module from basic.py. Also, if it helps, I am using python 3.9.6. Any help or suggestions are greatly appreciated.
You need to select the interpreter by following the docs.
Through the python extension, you can set the interpreter so that the packages will be taken from the environment. The interpreter is basically the python that your virtual env uses so it has access to the python packages that you installed in the virtual env.
Here are the steps in case the docs change:
CTRL+Shift+P or Command+Shift+P depending on if you're on Windows or Mac respectively
Type Python: Select Interpreter after the >
Then you can either select the interpreter from your virtual env that you created or enter the path to the interpreter.
Did you select the interpreter inside the vscode?
Enter vscode and type
ctrl+shift+p
and type in command prompt
>python:Select Interpreter
and then activate the Interpreter.
This will do the trick for you.
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.
I'm trying to set up a new dev environment on Windows 10. Let me set the stage with some key points:
I am using Ubuntu through Windows Subsystem for Linux (WSL).
I have Anaconda3 installed on WSL.
I have PyCharm installed on Windows 10.
I am attempting to use a Conda environment created in the WSL within PyCharm on Windows 10. For some reason I cannot find documentation or guidance on the process.
I have already successfully setup a virtualenv within WSL as a remote interpreter for PyCharm however it will not allow me to do the same with a Conda environment.
This was possible by using the absolute path for the conda interpreter from within PyCharm.
e.g.
C:\Users\winuser\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home\wslusr\anaconda3\envs\myenv\bin
It is now (as of very recently) not.
After some trial and error along with contacting JetBrains support, it was determined currently not possible.
My solution to get around this was to have Anaconda installed on both Windows and WSL and then create the Conda environment within Windows. I was then able to activate this environment within WSL with the absolute path to the environment.
Not the best approach but allows for editing in WSL and usage of the interpreter in PyCharm.
In your project in Pycharm.
Choose File, Setting, Project, Python Interpreter, Add
Choose WSL on the left. Linux = your Ubuntu
Python interpreter path = home/<your_name>/miniconda3/envs/<your_env>/bin/python3 -- this is the environment you have created in Ubuntu with Conda.
I haven't been able to confirm that yet, but for me it seems that the direct integration of WSL in PyCharm as Interpreter (like describede here: https://www.jetbrains.com/help/pycharm/using-wsl-as-a-remote-interpreter.html) is only possible when using the Professional Version of PyCharm and not the Community Edition.
There is a way you can use all the conda environments in wsl as well.
Install Anaconda or Miniconda in your wsl
Set the CONDA_ENVS_PATH environment variable in your wsl to where your conda environments reside.
(By default it will be /Users/.../anaconda3/envs/)
That's it after you restart your terminal and type conda list env. You can see all your environments in windows.
Incase if you dont know how to custom path for your cond envs:
check custom
I haven't used Python in a while, and only in Linux. Now on Windows, and just installed 3.7.4. I noticed immediately that python3.exe is not in the install directory, nor any of the pythonX.x.exe files, that are used for compatibility. I can only access Python through "python" from my command prompt, and old scripts that use Python 3 won't work.
Is there something I am missing here?
Of course, I can solve this for now by using symlinks, but is this an error in 3.7.4, or more likely, have I done something wrong in setting up my environment on Windows?
No, there's nothing wrong. This is just how Python is on Windows. There's the py launcher too that might help you out here.
https://docs.python.org/3/using/windows.html
3.2 The Microsoft Store Package
All three commands are also available with version number suffixes, for example, as python3.exe and python3.x.exe as well as python.exe (where 3.x is the specific version you want to launch, such as 3.7).
Virtual environments can be created with python -m venv and activated and used as normal.
If you have installed another version of Python and added it to your PATH variable, it will be available as python.exe rather than the one from the Microsoft Store. To access the new installation, use python3.exe or python3.x.exe.
By default I had python-2.6 installed on my Centos. I installed python-3.6.1 and Pycharm IDE. When I open settings of my Pycharm I can't see new interpreter for python-3.6.1. How do I locate and add the new interpreter?
How did you install python-3.6.1? Also, why not search for the python3 executable? I don't specifically know about Centos, but on UNIX systems it could be in /usr/bin/python3
Documentation based on Windows version, on mac is pretty the same, I'm not familiar with Linux version GUI, but should be very similar https://www.jetbrains.com/help/pycharm/configuring-python-interpreter-for-a-project.html
In short, point to the Python executable by adding local interpreter in Pycharm project settings http://imgur.com/ekvC0bM