I am experiencing a very similar problem to this one:
Using multiple versions of Python
The context of my problem though I believe is different enough to warrant a separate question. I receive this error when trying to launch the non-commercial version of The Foundry's Nuke. The error manifests similarly to this:
http://community.thefoundry.co.uk/discussion/topic.aspx?f=197&t=113695
,except the error message returned before the command prompt immediately closes is that displayed in the first link. This leads me to believe that Nuke is trying to access the wrong version of Python (currently it is trying to access
Python 3.5).
Assuming my line of thinking is correct, how can I change the version of Python that Nuke is attempting to access? None of the advice in the Foundry forum link proved successful either, I should mention. And according to what I have read,the latest version of Python to be used by Nuke is 2.7. So to ask the question more specifically, how can I make Nuke access Python 2.7 as opposed to Python 3.5? Both are installed on my desktop, 64-bit Windows 10.
The syntax error returned as the prompt closes and Nuke fails to launch
I have removed PYTHONPATH from System variables and Nuke9.0v8 non-commercial now appears to function properly. As this has not caused any problems with other applications and programs that rely upon Python 2.7 or 3.x, I believe this solution was sufficient in solving the problem I initially proposed. Previously I had specified the location of Python 3 within the Path variable, and this I have NOT modified. I imagine that this solution should be applicable to any software that generates the error message linked in the question.
Related
The language interpreter is set to a Python 3.9 version:
But a Python scratch file is being parsed by some kind of 3.6 interpreter:
Note that I created in two different scratch files and the same error occurs. Why would this happen and is there a workaround [short of creating an entirely new project from scratch]?
I am on Pycharm Professional 2021.3.1
Update based on answer by #TurePaisson he though maybe the Code is compatible with specific Python were set. That was a shrewd guess - but turns out I have not set that:
Update The following snippet can be used to test python3.6 vs 3.8+
x = (y := 3) + 7
In the preferences dialog, search for "versions" and you will find, under Editor/Inspections, an inspection "Code is compatible with specific Python versions" with checkboxes for which versions to check against.
I ended up creating a new python interpeter with version 3.9 and selecting it for the project interpreter. There's clearly some bug within Pycharm that it does not always cleanly switch among interpeters/versions - so starting from scratch is sometimes apparently needed.
I'll start by saying that I tried googling the exact error message and there aren't any significant hits (that's reason alone to post this leaving it as a roadsign):
"Python version 3.6 does not support assignment expressions"
I tried this with PyCharm versions 2021.2.2, 2021.2.4 and 2022.1 Pro (switching between Python 3.6 and Python 3.9) but I wasn't able to reproduce the exact problem that's shown in the question (I was unable to update to the exact 2021.3.1) and there might be some Project setting that's not obvious.
So I have 2 hunches:
It's possible there's something stuck with the inspection profiles since the OP seems to be working from a repository.
From experience my next guess would be to try and change the interpreter version of the "run configuration" because it's not stated explicitly in the documentation if it supersedes the project-wide interpreter chosen in Settings > Project > Python Interpreter for linter inspections. From my tests it currently doesn't but apparently it worked for the OP... Maybe by rebuilding the index and refreshing the background linter process.
Following up on #bad_coder 's attempt to fix that will be paraphrased as:
check the Run Configuration for pointing to a different python interpreter than the project level one
That fix worked for me:
Bring up the Run [Context menu] | Edit Configurations
Change the Python interpreter to the appropriate one: Shown below is a case where the interpreter is said to the earlier language level. Go to the dropdown and select a correct [python 3.8+] interpeter.
I want to avoid
these kind of messages popping up, as I am not even using python 2.7. Note that the code runs fine.
I have tried the following things:
Unchecking 'Code compatibility inspection'
Checking 'Code compatibility inspection', but unchecking python 2.7
Invalidate Caches/Restart
Editing '.idea/misc.xml': component/version from 2 to 3
I am using a .sh wrapper around the python executable on the server as I want Pycharm to first source my ~/.bash_profile before using the interpreter (similar to this advice).
I think that this might be the reason PyCharm doesn't recognize it as being python 3: if I point directly to the remote interpreter, the code compatibility issue dissappears.
Is there any way to keep the benefits of the wrapper and getting rid of these error messages?
You're right, PyCharm is unable to determine Python version and uses 2.7 as a fallback.
Since 2019.3 the latest Python is used by default (3.8 at the moment), please try the EAP build.
Edited to include a specific example
I am learning to use python and work in a windows 10 environment (although on 3 separate computers). I have gotten past the "add python to %PATH% issue" but continue to see odd outcomes when I call simple scripts from powershell compared to running them from the python terminal. For example, I often see that lines of code are duplicated, even simple print statements. A second repeating issue is that some (but not all) modules work fine in the python terminal but can't be found when running a script from powershell, despite using pip install within powershell to install it in the first place.
Rather then seeking help on a specific issue, I'm hoping for some guidance into how powershell and python interact that might help me understand or identify some commonalities in these issues I keep experiencing that are common from within powershell. If thats as simple as redirecting me towards another source even that'd be apprecaited. But my search results always turn up the common issue of powershell not knowing what python is, and needing to add python to the PATH. But as indicated, I have already gotten past this and can get %50 of my python to work from powershell. There must be something else perhaps obvious to others that I'm missing that can help me understand why some things aren't working while others are.
Thanks for taking the time to consider my problem and any advice is greatly apprecaited.
Here is an example from some code I am trying to get working, but in troubleshooting I have taken out a lot of code and am now only running what is shown that defines a dataframe and a print statement. Everything works line by line in python, but when I call the script from powershell, the print statement executes twice.
#!/usr/bin/python3
import pandas as pd
joedata = {'fpr': [0.2,0.4,0.8], 'tpr':[0.9,0.5,0.1]}
joeframe = pd.DataFrame(data=joedata)
print(joeframe)
Concerning modules, you probably have multiple versions of Python installed on your system. Calling pip in the Powershell doesn't mean that it will install for the Python installation which is called by default when you execute Python in the Powershell. So you should try to figure out on which version pip is installing packages and which version is actually used when executing a script.
EDIT: I tested the example that you gave in Powershell and I don't have the problem, it's working fine.
Moreover, for me, without doing any special configuration, in Powershell the commands pip and python refer to the same version of Python. If by default everything is ok, you should consider uninstalling Python and just running the installer again and let it manage the PATH, etc.
I would like the most advanced version of Python that still works on Windows XP. I need both Python 2 and Python 3.
What versions of Python will work on Windows XP?
I found that Python 2.7.9 and Python 3.4.4 are the newest versions of Python that work in Windows XP. I found this out through trial and error.
I've found a desperate guy (Daniel Pistelli) who didn't give up at the windows error dialog:
https://ntcore.com/?p=458
I like how he approaches the topic:
If we try to start any new application on XP, we’ll get an error
message informing us that it is not a valid Win32 application. This
happens because of some fields in the Optional Header of the Portable
Executable.
[...]
Fortunately, it’s enough to adjust the fields in the executable we want to start (python.exe), there’s no need to adjust the DLLs as well. If we try run the application now, we’ll get an error message due to a missing API in kernel32. So let’s turn our attention to the imports.
And then he goes on for another 5-6 screens. To sum it up, apparently you'll have to:
Modify the python.exe header,
Run a tiny Python script to remap some DLL calls,
Recalculate some binary hashes,
Create a fake kernel32.dll with certain calls forwarded,
Modify python37.dll to point to this fake thing,
and then you're all set. To be honest I couldn't quite follow (let alone verify!) some of the steps but it looks legit and there are links with Daniel's half-baked solutions for the harder parts, also a lot of Python sources explained. I will definitely give this thing a try.
In fact, here are the final scripts from his GitHub page:
https://github.com/dpistelli/xptmrt
Moral of the story: you can be crazy, but you'll never be dismantle-all-dlls-and-exes-and-open-hexeditors-and-disassemble-hashing-algorithms-and-mock-it-all-together-so-it-works-under-xp-crazy!
Someone had built Python 3.4.10, which is slightly newer than the officially prescribed Python3 v3.4.3/3.4.4 for Windows XP. Since it comes from the third-party (not the official Python website), use at your own risk,
-->Download<--
i tried 3.3.3 but i came up with an error message use 3.4.3/2.7.9 they are the only versions that work now sadly
There are several custom builds of Python >3.44 suitable for Windows XP. A poster at reddit has provided Python 3.55 here:
https://www.reddit.com/r/Python/comments/3tgi0t/python_35_x86_on_windows_xp/
Here is an XP compatible build of 3.6.15 source code only:
https://alex-free.github.io/winxp_python3.6.15/
At the MSFN forums someone has provided an XP compatible build of 3.8.1350 here:
https://msfn.org/board/topic/183741-python-3813-for-windows-xp-sp3/
Official website says about 3.4.10: https://www.python.org/downloads/release/python-3410/
Any of them, python is very platform independent. Some features might not work, but that would best be found in the documentation.
I have had trouble setting up the pycharm ide on my macosx10.7 with python3..
I have scoured every resource available and tried hundreds of approaches, at this point I must accept my incompetence and seek help via this channel.
In my research, I notice a lack of ground-up explanations on python integration into macosx and how to configure pycharm to import modules, run code within the editor, etc. If i ever solve this I will make a very detailed tutorial.
I have imported python3 successfully, it looks like it is linked appropriately from /sys/lib/frameworks to /usr/lib ...etc -- version control is working just fine.
I think my issue is either in setting environmental variables (tried the program to fix this and tried macports) and in the script needed to execute. it will catch errors throughout but final product does not run in python and returns printout of :
/Library/Frameworks/Python.framework/Versions/3.2/bin/python3.2 /Users/anon/Desktop/pythonpractice/Py_Ex/classes.py
Process finished with exit code 0
i really need to get this configuration sound for my python programming class. please help (I've been through every line of pycharm website) .. preferably is there a way to map it via terminal? thanks for anyone who took the time to read this.
Summary of the discussion above:
Python 3.2.2 installation was broken on this Mac, installing ActiveState Python 3.2.2 from scratch and configuring it in PyCharm has fixed the problem.
Python path to be used in PyCharm settings: /Library/Frameworks/Python.framework/Versions/3.2/bin/python3
Incompatible third-party plug-ins may break PyCharm, uninstall/disable them in Preferences | Plugins.
Ensure the latest PyCharm version is installed.
User's code depends on the graphics.py module which was not in the project or in the PYTHONPATH. Putting it into the project has solved the problem.
Most likely the wrong Run/Debug configuration was used in PyCharm, the easiest way to run or debug such scripts is by using the editor context menu Run and Debug actions. PyCharm creates the configuration automatically and debugging works fine as shown of the screenshot:
If one wants to configure and debug it, he can use the code.zip file to get started.
Sorry for the comments mess above, but it was not possible to move it into chat as user had only 1 reputation point, hence not able to use the chat feature of StackOverflow.