Python not found - python

I'm working on a project in a python virtual environment, the project was started on a pc with python 3.8 installed and consequently python 3.8 was used in the virtual environment, or I had the need to continue the project on another pc, so I loaded all on GitHub, in the end I downloaded it to another PC with python 3.11 installed, the files are all there but when I try, inside the virtual environment, to open python by writing python or python3 in the terminal, it shows up this error: Python not found; Run with no arguments to install from the Microsoft Store or disable the link from Settings > Manage apps Run aliases. I then tried to see if it only showed up inside the virtual environment, but the same thing happens outside as well.
I tried to do various things among those suggested in other forums but they didn't work, the problem persists, I'm a bit lost, it's the first time this has happened to me.
Sorry to bother, maybe it's the simplest problem there is to solve but I don't know where to start
Trhanks

The problem is the different version of python on the two computers... the content of the pyvenv.cfg file must simply be changed which, when creating the virtual environment, is based on the installed version. Here you just need to change the path to reach the python.exe file installed on your computer and then change its version by inserting the correct one.

Related

Python inside a virtualenv is broken (Django)

TL;DR - Microsoft Store Apps are broken (0 bytes), hence the Python interpreter is unable to create process and run "Python" inside virtualenv, I failed to follow numerous explanations of how to change virtualenv path for Python.
Recently, without any changes to my computer/environment, an issue started occurring when executing (also tried python3, which brings the same):
python manage.py runserver
This brought back the following issue:
Unable to create process using
'"C:\Users\MyUser\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\python.exe"'
As I dug deeper, I realized that all of the apps installed under this folder are 0 bytes, hence they are completed broken, all of a sudden.
Therefore I figured it's not an issue with Django, rather the python itself.
I tried changing the virtualenv path for Python.exe, instead of using WindowsApps version, I installed the original Python from the original website.
I failed to do so, multiple times.
I tried: "https://stackoverflow.com/questions/4757178/how-do-you-set-your-pythonpath-in-an-already-created-virtualenv/47184788#47184788" - Adding the path inside "activate" and "activate.bat", as
set PYTHONPATH="C:\Users\MyUser\AppData\Local\Programs\Python\Python310\python.exe"
And the issue persists.
I tried every solution/article I found in regards to the issue I have. Many of them claim a simple result, whereas the rest claim a complete refactor is required.
Even downloading from Microsoft store is broken, it always fails.
Since I'm unable to remove the broken apps, and I wasn't able to find a way to change the virtualenv Python interpreter, I am here, asking for your assistance.
Thanks in advance,
Since you have installed python from python.org, ensure that it has been properly added to the PATH and you're not inadvertently using the windows store version.
Open command prompt
Execute where python to check which python your system is using.
If you're only seeing the WindowsApps version of python listed in the output of where command, then python installer apparently didn't add the location to PATH, so you'll need to manually add it yourself.
Also, if you're not restricted to use virtualenv, you can give conda a try.
As I began rebuilding, I figured it out.
When building a virtualenv, the python I used was directing to:
"C:\Users\MyUser\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\python.exe"'
Python interpreter is saved as the "PATH" to execute python.
Since my Python interpreter from Microsoft Store went broke, I was unable to execute python inside the virtual environment.
Venv configures a file called:
pyvenv.cfg
This is how the virtual environment knows what Python interpreter to use.
Inside it, the first line states:
home = C:\Users\MyUser\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\
Therefore, we just need to re-configure it to the new path of Python interpreter:
home = C:\Users\MyUser\AppData\Local\Programs\Python\Python310
And it worked for me.
Thanks for everyone's assistant, glad it's done.

How do Windows Paths and Anaconda virtual environments work together?

I started my Python journey a month ago by following a guide which recommended installing Anaconda. Since then I've written/adapted some Jupyter Notebooks using VS Code and run them from within virtual environments. Recently I needed to run one of these Notebooks via from MS Access VBA and got to understand a little about using Python from the command line - specifically about using Environment Variable Path functionality in Windows to access Anaconda\Scripts and use things like activate to active virtual environments.
In the video guide it also recommended adding Anaconda3 to my Path so I could access python.exe. However, I've held off doing this because even after plenty of reading I'm still not clear on exactly the mechanics of of using this command when working with Anaconda virtual environments.
So to my question... say I add the Anaconda3 folder to my Path and then write something like python myscript.py presumably it runs the python.exe interpreter from the Anaconda3 folder? How will this work if I'm in a virtual environment that needs Python 3.7 but the interpreter I've loaded is actually Python 3.6? Does this even matter?
Please be assured I've read for a couple of hours on this before posting my question. Happy to read more if there is a layperson guide someone can point me towards. I've read through the Anaconda site.

PyCharm always thows this error on creating new project and interpreter(virtual env) is missing for the project

I have got a problem with pycharm. I reinstalled everything(system python, anaconda, pycharm) since I thought it was conflicting with Anaconda. Finally, I completely got rid of Anaconda and still Pycharm throws the following error whenever I create a new project.
Unable to create process using 'C:\Users\Ritanshu Singh\AppData\Local\Programs\Python\Python37\python.exe
"C:\Program Files\JetBrains\PyCharm Community Edition
2018.3.2\helpers\packaging_tool.py" list'
Also the project(virtual env) interpreter is missing every time I create a new project(My actual system python is installed and works well, I have tried and run a raw python text file) and I can't run the python code. I googled but it shows no results.
I figured out that it has a problem to create virtual environment interpreter but I don't know why? The error code is above listed.
There is a very good documentation available for configuring the python interpreter in Pycharm: https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html and
https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html
Please verify that you follow these steps before starting the Pycharm.
Do not import config.
Check the user permission which starts the Pycharm(Administrative).
Add path variable for python in windows.
install and configure the pip that will help you to download the package while setting up the interpreter.
I found that from Python version 3.3+, the built-in venv module is used, instead of the third-party virtualenv utility. It is written on PyCharm Official Page on this link: https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html

How to set default interpreter and keep things in order?

I was required to install anaconda for a CS course and used spyder and Rstudio.
Then, for a different class I used pycharm.
When I type on the command line "python -V" I get:
Python 3.6.1 :: Anaconda 4.4.0 (x86_64)
and I have no idea why it relates the python version I have installed with Anaconda (and why not pycharm?). I understand that the OS runs python 2.7 (shouldn't I get that instead? and when I type python3 -V get which version of python 3 I have?) and when I use something like Pycharm or Spyder I can choose which version I want from the ones I have installed and use it within the program, not for the terminal.
I just want to have everything in order and under control. I don't think I understand what Anaconda really is (to me is like a program that has more programs in it...). How do I keep anaconda to itself ? 1313
Also, should the packages I installed through Terminal work on both pycharm and spyder/anaconda even though when I used pycharm I used python 3.5 and anaconda 3.6?
I think I need definitions and help to get everything in order in my head and the computer.
Pycharm is just an application to help you write code. Pycharm itself does not run python code. This is why in PyCharm, you need to set the interpreter for a project, which could be any python binary. In PyCharm, go to Preferences > Project > Project Interpreter to see where you would set the python environment being used for a given project. This could point to any python installation on your machine, whether that is the python 2.7 located at /usr/bin/python or a virtual environment in your project dir.
The industry standard way to "keep things in order" is to use what are called virtual environments. See here: https://docs.python.org/3/library/venv.html. A virtual environment is literally just a copy of a python environment (binaries and everything) so whatever directory you specify. This allows you to configure your environment to however you need in your project without interfering with other projects you might have. For example, say project A requires django 1.9.2 but project b requires 1.5.3. By having a virtual environment for each project, dependencies won't conflict.
Since you have python3.6, I would recommend going to you project directory in a terminal window. Running python -m venv .venv to create a hidden directory which contains a local python environment of whatever your 3.6 python installation. You could then set your project interpret to use that environment. to connect to it on the command line, run source .venv/bin/activate from where you created your virtual environment. run which python again and see that python is now referencing your virtual environment :)
If you are using a mac (which I believe you are from what you said about python2.7), what likely happened is that your anaconda installer put the Python bin directory on your PATH environment variable. Type in which python to see what the python alias is referencing. You can undo this if you want by editing your ~/.bash_profile file if you really want.
You are more or less correct about anaconda. It is itself another distribution of python and contains a load of common libraries/dependencies that tend to make life easier. For a lot of data analysis, you likely won't even need to install another dependency with pip after downloading anaconda.
I suspect this won't be all too helpful at first as it is a lot to learn, but hopefully this points you in the right direction.

PTVS cant find Python interpreter?

I just copied my Flask project from one machine to another. I have same version of Python installed on both the machines. When I loaded the project in the new machine, it said my virtual environment is unavailable. So I initially tried to install it from requirements.txt file but it failed without any helpful error message.
So I deleted the virtual env in Visual Studio and tried to create another one. Now it complains that it cannot find any Python interpreters on my machine. I tried uninstall/reinstall Python but it didn't work. Also, the Python location is added in the PATH environment variable and all the modules in the requirements.txt file are downloaded from pip individually.
So the modules are installed, python is installed and the project is there but the virtual env won't setup because of the below reason. Any way that I can fix this ? This is PTVS15 and Python 3.6.1
Fixed it myself. I went ahead and added the environment manually by specifying the Python installation paths in the Add Environment tab. It took a while to detect the interpreter even in this way but it finally worked. I am now able to build my app.

Categories