I'm trying to run a program with poetry but it keeps using the wrong version of python.
when I use
poetry shell
It outputs
The currently activated Python version 3.9.5 is not supported by the project (>=3.10,<3.11).
Trying to find and use a compatible version.
Using python3 (3.10.4)
Which is what I want. It SHOULD use python 3.10. But I don't know why it thinks python 3.9.5 is "activated." But when I use
poetry env info
It gives me
Virtualenv
Python: 3.9.5
Implementation: CPython
Path: /Users/myname/Library/Caches/pypoetry/virtualenvs/app_name-dNeoDE2I-py3.10
Valid: True
Which is strange, it has a file called py3.10 but it sees as 3.9 and when I use it it runs as 3.9
--------------------------------------------------------------------------------------------------------
I've tried a couple things to remedy this.
poetry env use /path/to/my/python/3.10/verion/that/works/outside/poetry
Yet, this changes nothing
You need to run this:
poetry config virtualenvs.prefer-active-python true
Next, remove and create the python virtual environment again. This is what worked for me.
See the documentation please: https://python-poetry.org/docs/configuration/#virtualenvsprefer-active-python-experimental
Related
I am trying to use Python3 with PyCharm.
So I installed Python(3.10.1) and PyCharm(2021.3.1)
But when I try to create a new project, PyCharm want me to choose 'base interpreter'
and I don't know which one to choose.
Here is the list of base interpreter:
I want to know what is difference between /usr/bin/python3 and Library/Frameworks/Python.framework/Versions/3.10/bin/python3
Usually the files under /usr/bin/ are symlinks to actual files, which means they are not real files but links to the actual file.
To see it for yourself go to the /usr/bin/ directory with a terminal and execute:
ls -a
I suppose macOS already ships with python and by installing Python 3.10 you added that last element to the list, which is also linked by /bin/usr/python3.
I'd go with /usr/bin/python3, more portable.
You can choose the one interpreter for the version of python you want. In your terminal, you can run python --version or python3 --version and it will display the version of python, Like this:
$ python --version
Python 2.7.16
$ python3 --version
Python 3.9.1
Performing which python, will give you the path to that python binary, like the following (although, this is where we are leaving "Python" and talking more about the OS and PATH.
$ which python3
/usr/local/bin/python3
For the other versions of Python you have installed, you can check their version by doing something like:
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3 --version
You'll find that you may choose different versions of python for different projects. In the future, you may consider using venv to setup virtual python environments per project.
If you're just getting started with Python, I'd suggest sticking with the version you installed 3.10.1, and choosing that interpreter.
The base interpreter is the python.exe file that will run everything you do inside that project.
I would suggest you use Anaconda as a package manager and then create a virtual environment with the version of Python you need. Just follow these steps:
Getting started with Anaconda: https://docs.anaconda.com/anaconda/user-guide/tasks/pycharm/
Choosing an Anaconda virtual environment with Pycharm:
https://docs.anaconda.com/anaconda/user-guide/tasks/pycharm/
A package manager like Anaconda is very useful when working with Python.
Otherwise:
In your list you have many different versions of python. You should choose the base interpreter based on the python version you want to use.
Always select the latest version.
Since I use Python 3.9, it will be:
/usr/local/bin/python3.9
Based on your image, it would be:
/usr/local/bin/python3
The interpreter is what version your PyCharm project uses. It appears you have python2 and python3, so if you were writing in python2, you would use the python2 interpreter.
I would select the latest version, which in your case would be:
/usr/local/bin/python3
So here is my story:
As we know macos comes with pyhton 2.7 preinstalled. Years ago, I installed python 3.7.0 and all going good. I started working with Tensorflow and during that time tensorflow wasn't compatible with 3.7.0 so switch the version to 3.6.6 somehow :). After some time i installed anaconda and it installed 3.7.3.
At this point:
When i open my python IDLE shell, it runs on 3.6.6
anaconda Jupiter notebook shows 3.7.3.
Then i learned to create virtual environments through terminal and i use following code to create virtual environment:
pip install virtualenv
virtualenv project_env
And after i activate the virtual environment the python version it shows is 3.7.3.
Then recently i changed the terminal shell to zsh and now everything is kind of messed up. I'm
Terminal can't find conda commands. How to fix that?
Now i can't create virtual environment through virtualenv project_env. It says command not found. Why? It use to create virtual environments with python 3.7.3.
Now to create virtual environment i use python3 -m venv project_env this creates the virtual environment with python 3.6.6. If i use python3.7 -m venv project_env it creates environment with python 3.7.0.
I can't find a way to create virtual environments with python 3.7.3.
I need help with above troubles caused after installing zsh and help with accessing python versions wherever i need. How do i update python version 3.7.0 to latest or any specific version like 3.7.3. Hows python 3.8.4 to use, i mean like i had trouble importing tensorflow in python 3.7.0.
I hope you will understand my trouble and searched a lot for solutions. I'm so confused right now, couldn't even figure out the title of my problem.
Based on the fact your shell can't find conda now, you should look at your "path" environment variable. Whenever you change from one shell to another, you need to look at and possible create or modify the files the shell uses upon startup. These files setup your environment (PATH, PYTHONPATH, etc), create aliases, etc. You may need to create the .zshrc, .zprofile, .zlogin etc files and add the same settings as your previous shell's startup files.
Example:
If you used the bash shell previously you would need to modify the .zshrc file to include your settings in the .bashrc file. Syntax may be different, so a straight copy may or may not work.
Try this as a quick temporary fix (may or may not work, depending on your current ~/.profile settings:
Create a ~/.zprofile file with this code inside:
emulate sh
. ~/.profile
emulate zsh
references:
https://superuser.com/questions/187639/zsh-not-hitting-profile
http://zsh.sourceforge.net/Intro/intro_3.html
I am new to Python and couldn't find this answer online.
When creating a Python Flask application, what exactly determines the Python version used? I inherited an existing Python Flask application that is currently version 3.6 and wanted to upgrade it to a newer version.
Is this as simple as changing the Python version that is installed on the environment that runs the Python application or is the specific version defined in a project file?
I have tried updating the version of Python in my local environment but the project version did not change.
What you might have right now is python3 corresponding to 3.6 and python corresponding to 2.x.
You could install a new version of python; in this case 3.8 by downloading it from python website here and install it as python3.8 instead of replacing python3 or python.
Once installed, you could run virtual env with the -p or --python and passing the path to the executable as the argument as follows
python3.8 -m venv path/for/venv/py3.8
Once it's set up, source it and check out the python version.
what exactly determines the Python version used?
You can write whichever Python style you want in the project (2.x or 3.x) as long as it is supported for the version of Flask you are using.
What "determines" the version it executes with is which version of Python you specify when you start Flask. As in "python app.py" or "python3 app.py" will start with either version etc.
I have a specific problem with python. I have on my ubuntu two versions python3.4 and python3.6(from anaconda). I want use just anaconda pythoncurrent version
But when i run script i have some problems with another python version
another version
How i can safe delete useless python 3.4.6?
sudo apt-get remove python3.4
anaconda should have set python3 as default python3.6 version
You should probably not delete Python3 from your system, even if you have Anaconda installed, since there might be system software that:
was not tested with subsequent versions of Python;
might struggle finding Python from Anaconda.
What you should do instead is configure your IDE / environment to run Python script with Anaconda, e.g. by setting your PATH variable to point to your anaconda/bin directory or similar.
If you are using PyCharm, as it seems from the screenshot, you could set up your project to run the Anaconda Python without modifying your other command-line settings.
I'm trying to understand how to create an isolated python environment using an alternative version of Python other than the default (in my case this is Python 2.7). virtualenv works on my system with Python 2.7, but I can't seem to create a virtual environment with a version of Python 3.
I tried to specify the Python version as outlined in this this post, like this:
$ virtualenv -p /usr/bin/python3.2
Can anyone explain how I can create a virtualenv with a specific version of Python? Thanks very much.
I believe you need to install python 3.2 to the system first. You're telling the virtualenvironment to use a version of python that doesn't exist anywhere so it cannot find it. This is the "does not exist"
Edit after more info was given in comment:
virtualenv -p /usr/local/bin/python3.2