All.
I'm trying use Python in VS Code. I've installed Python 3.7 and Python extension in VS Code. I've chosen correct interpreter, but when I tried run my script, it's still using Python 2.7.
I've wrote simple test script:
import sys
if __name__ == "__main__":
print(sys.path)
and I got:
'/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages'
I've checked my VS code settings founded there python.pythonPath with value /usr/bin/python3.
I've added Python 3.6 to PATH.
I've read https://stackoverflow.com/a/55182584/11222097. None of the above methods worked.
I don't know what more I can do to make VS Code use the correct Python version.
Related
I have the following problem with fbs and Python: I tried to compile Python code and wanted to create an executable .exe file in windows. The command fbs run works fine, but fbs freeze fails.
Package versions:
Python 3.6.4
PyInstaller: 3.4
PyQt5: 5.9.2
Packages that I import:
import re
from itertools import chain
import os
import pandas
from PyQt5.QtWidgets import *
from fbs_runtime.application_context.PyQt5 import ApplicationContext
The output of fbs freeze --debug you see in the attached image:
I used the pyinstaller command to create the exe. This was possible without fbs. Just pyinstaller with the standard comments pyinstaller "...." --onefile --noconsole.
It worked with Python 3.6.4 and pyinstaller 3.4. Perhaps 3.5 would also work. But I know at least that Python 3.8.0 with the newest pyinstaller (even development version from git) doesn't work. I used PyQt5, but some older version 5.12....
It's a bit intransparent...
Best regards,
Markus
fbs runs perfectly fine with python 3.6.x (I am using 3.6.8, PyQt 5.9.2, PyInstaller 3.4).
The python compiler can sometimes get confused if another error happens earlier in the stack. Generally if fbs freeze errors when fbs run works, that points to a library-include error.
See my answer here to include necessary python library resources in your ./src/freeze/windows/ directory and try freezing again: The 'google-api-python-client' distribution was not found and is required by the application with pyinstaller
im fairly new to programming in Python and i've been using the terminal to run my code with no problem. Usually by typing python {filename} to run it.
However, recently i got this error:
ImportError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.
then i changed the python {filename} to pythonw {filename} and the code worked. Could someone give me some insight into this error and why it worked by just adding w?
pythonw - run python script allowing GUI. According to the man page for pythonw.
I tried using select python interpreter and chose my virtualenv using python3 but when I use print(sys.version) on the file I create in vs code, I still get python 2.7. What am I doing wrong?
I'm still learning python. I have windows 8 and had downloaded 2.7 as well as 3.5 because two modules I used in the past respectively used different python versions. Now though, I'm trying to run a script where the first line is import http.client or http. Neither of these work though. In cmd, python returns 3.5.1 currently and import http.client and import http return with no errors but in my IDE these don't work. Why not?
You can follow the Pycharm documentation here to change the Python version for your project from Python 2 to Python 3.
(In particular, Selecting Python interpreter for a project section)
I have both 2.7 and 3.0 versions of the Python interpreter installed (on my Ubuntu 32 system), but one particular script uses 3.0.
Using
#!/usr/bin/python3 -B
will not work when the program is run with python myprogram.py.
And I also need a solution that works also in Windows where I also have both python versions installed.
How can I make the script to run only with the right python version?
Please use virtualenv, which makes isolated Python environments easy.
python = Python to use. # This has to be the absolute path to Python executable
os.execl(python, python, * sys.argv)
This way you can restart the script with the python you want to use. Not really stylish.
I don't know why you can't just launch the program with python3 foo.py, but it's possible to have a python2 program relaunch itself as python3 with something like this.
import sys
if sys.version_info.major != 3:
import os
# replace this process with a python3 process
os.execlp("python3", "python3", *sys.argv)
It's a bad solution though, because now your python3 program can't use anything that's not valid python2 syntax
Please take a look at The wrong python interpreter is called
You have to choose a correct interpreter based on where you installed the desired version of Python and your system variables.