I installed Python 2.7 a long time ago on my PC (I am running Windows 10). Today I decided to install Python 3.7, but after typing 'python' into the command prompt the console printed 'python 2.7...'
I have no idea as to what I should do. Would this be a problem with my path configuration? I considered uninstalling python 2.7 but I still want it installed on my computer.
Configure multiple Python versions on Windows
Python 3.3 introduced the Python Launcher for Windows. Rather than using python.exe, call py and select the version with flags:
py -2.7
py -3
System-wide installations of Python 3.3 and later will put the launcher on your PATH.
Note on Virtual Environments (new in Python 3.5)
If the launcher is run with no explicit Python version specification, and a virtual environment (created with the standard library venv module or the external virtualenv tool) active, the launcher will run the virtual environment’s interpreter rather than the global one. To run the global interpreter, either deactivate the virtual environment, or explicitly specify the global Python version.
Outdated Method (not recommended)
Rename executables - After installing multiple versions, change the names of the executables. For example, for Python 2.7, under the installation folder, rename python.exe to python27.exe and rename Python 3.7 from python.exe to python37.exe. Then on the command line, select the version by entering python27 or python37. Whichever version is preferred, could be left as just python.
Add Path Environment Variables - For example, on Windows 10, go to the Windows menu and search for "environment variables" and click edit the system environment variables. In the System Properties dialog, click Environment Variables.... Under "System variables", select "Path". Click Edit.... Click New and add the first entry below. Click New again for each Path variable entry.
C:\Python27
C:\Python27\Scripts
C:\Python37
C:\Python37\Scripts
This will enable Python and pip. Be sure that paths match your actual installation directories.
I would suggest using pyenv
I have been using it and is working well for me. Some of the handy features of pyenv are
It allows installing multiple version on python easily
It allows switching python version with one command in global, shell or folder level
It also allows creating virtual env using virtualevn extension
I would suggest to use virtual environment. Soon or later you would you might get dependency problems.
You Can Configure The Python2 & python3 In Windows PC Like This:
First Of All Install Python 2 & Python 3 in windows PC in C directory like this:
C:\Python27 --> For Python2
C:\Python39 --> For Python3
After Installing Both Packages Go To Their Respective Folders And Copy python.exe & Paste In The Same Directory and rename the python - Copy with python2(In python27 folder) & python3(In python39 folder)
Python2:
Python3:
And Then Set Environment Vairable Like This:
All Done Now You Can Run Any Script Which May Compatible With Python2 or Python3 :)
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 want to create a virtual environment to install modules only required for a particular proj and for sharing whole package.
Versions that are installed in my system
Python 3.8.3 -- envvar set to python3
PyCharm 2020.1.2 (Community Edition)
Python 2.7(due to maya pyside2) -- envvar set to python
As per python docs
https://docs.python.org/3/library/venv.html#creating-virtual-environments
Deprecated since version 3.6: pyvenv was the recommended tool for creating virtual environments for Python 3.3 and 3.4, and is deprecated in Python 3.6.
Changed in version 3.5: The use of venv is now recommended for creating virtual environments.
I require PyQt5 for my current proj
and python3.8.3 was best suited so decided to go with it
and pycharm as my IDE
1) so i decided to create a virtual env through it but it prompts an error.
in case if the image is not displayed error was
2020.1.1\plugins\python-ce\helpers\packaging_tool.py pyvenv
Error:[WinError 2] The system cannot find the file specified
I don't get it why pycharm is not able to recognize the version of python3.5 and above.
2) so as per above docs i started searching venv for couple of hours and came across many pages eg: https://www.c-sharpcorner.com/article/steps-to-set-up-a-virtual-environment-for-python-development/
and referred the page and installed through pycharm the virtualenv and virtualenvwrapper-win and began the process again but this time through terminal and worked like a charm. env was created.
but as we know the python.exe is required in scripts folder to run anything but that was missing
3) that brings me to 3rd point i enforced the python persion with virtualenv path/venv -p python3.exe but still no sign of python in the environment.
and if i activate the environment "activate.bat" works fine
pip list in terminal
prompts me
Fatal error in launcher: Unable to create process using '"D:\All_Projs\Maya_Projs\succinct_save\venv\Scripts\python.exe" "D:\All_Projs\Maya_Projs\succinct_save\venv\Scripts\pip.exe" list': The system cannot find the file specified
Help appreciated
Thank You.
I have python 3.8 installed on my pc, but i need 3.7 for a specific task. When i try to set up a virtual environment via
virtualenv -p "my/path/to/python37.exe"
it calls the installer, so i am to install py37 manually, but then it ends up with an error:
Error 0x80070666: Cannot install a product when a newer version is installed
Is there a proper way to implement such a thing?
Thanks!
Have you tried anaconda or miniconda (the lighter version of anaconda)? Having more python versions in different environments and switching between them is quite easy.
I haven't installed Anaconda. If you want to have multiple different environments with pure Python you can do it like this:
1) Install the python versions that you want with the exe installer, ie Python 2.x.x, Python 3.7.x, Python 3.8.x etc, maybe inside a common folder like C:\Python
2) Then edit the System Variables path and pinpoint to the folder for the version you want to create a virtual environment. You need two entries here, one to python folder (for the python.exe) and one to the Scripts folder (for the pip.exe)
3) Open command prompt and hit python. You ll see that it's showing the apporpriate version. Install the virtual environment with "python -m venv name_of_env_you_want"
4) If you want to create a virtual environment with a different version change the paths
I'm using Pycharm Community 2018.1.4 on Linux Mint 19 Tara Xfce.
It works well with Python 3.5 interpreter.
I installed Python 3.7 to be the default Python interpreter on the system.
python -V command returns Python 3.7.0b3
I would like to use Python 3.7 in Pycharm.
I've tried :
which python
/usr/bin/python
which python3.7
/usr/local/bin/python3.7
When I go to File > Settings > Project and Interpreter > Add and there is no /usr/local folder and there is no python3.7 in /usr/bin
I can cd to /usr/local/bin folder in the terminal, but Pycharm just can't.
I restarted, uninstalled/reinstalled Pycharm, refreshed its inner browser, restarted my pc. Nothing changed.
What am I missing?
You will need to add the interpreter to the list of available interpreters.
Use which python to find out the path of the interpreter, then in the Settings > Project Interpreter > Add > System Interpreter window hit the "..." button and add that interpreter. (The screenshot below is from macOS, but it should be the same on Linux.)
I had the same issues with Pycharm Community Edition 2020.1, Linux Mint 19.3.
For reasons I don't know, the Flatpak version, which is only provided in Linux Mint's repositories can't see and access most of the directories which are beyond the user's home.
Pycharm 2020.1 Flatpak comes with a Python 3.7 interpreter, which seems to live in the virtual environment, located in the user's home.
I tried to change for the default python3 compiler of Linux Mint 19.3, which is version 3.6 and lives in /usr/bin - no chance, neither by navigating with Pycharm's file browser, nor by copy and paste to the path field.
Strangely also most of the directories e.g. below /usr/lib weren't displayed.
I then installed Pycharm via a ppa (alternative package repository for some Linux flavors), to be specific this one
VoilĂ ! Any installed interpreter is accessible and can be selected.
How do you launch Python3.7 in terminal? For example, you use python3.7 to launch.
Then you can which python3.7 to find where it is.
And then add that path to your Pycharm's Python Interpreter.
if you already have 3.7 installed. right click and run Pycharm as admin. then it should display, and install the new packages.
In flatpak-version PyCharm you can found host-os files in this directory:
/var/run/host/
For example:
/var/run/host/usr/bin/python3.8
But this is a bad way. It is better to install from the ppa.
use ctrl + alt + s to open interpreter the select the one you wanted to use that is for the environment you have chosen. If you wanted to change the interpreter for the environment the go to the interpreter settings after pressing the ctrl + alt + s and select the environment interpreter.