IntelliSense not working with Visual Studio Code/embeddable python - python

I want to use the embeddable version of python (3.7.0) in an windows 10 environment without need of an installer/admin permissions. Visual Studio Code is the IDE to be configured with the python interpreter above.
To install embeddable python, I followed the instructions of this answer and this issue and it works fine on CLI.
Setup VS Code according to this site:
installed Python extension and linter
added my python folder (root of python.exe) and subfolder \Scripts in PATH environment: C:/my/path/to/Python,C:/my/path/to/Python/Scripts
configured the interpreter like this in user settings: python.pythonPath": "C:/my/path/to/Python/python.exe
Sample script:
msg = "Hello World"
print(msg)
In VS Code I CAN execute the script by right click on active editor -> "Run Python file in terminal".
But I get no IntelliSense:
When I print the sys.path, it gives me
C:\my\path\to\Python\python37.zip
C:\my\path\to\Python\
C:\my\path\to\Python\lib\site-packages
Documentation for Python extension says nothing about embeddable python not been supported:
Install a version of Python 3 (for which this tutorial is written).
Options include:
(All operating systems) A download from python.org; typically use the
Download Python 3.6.5 button that appears first on the page (or
whatever is the latest version).
...
Any ideas how to solve this?

I was using the Python version from Anaconda but I was also not able to get Intellisense to display anything, similar to what you're describing.
In the end, the way that I got Python intellisense to start working in VS Code was to:
open up the Terminal (View menu => Terminal)
type conda init powershell
restart VS Code
After that, Python intellisense started working correctly.

I had the same issue of IntelliSense not working - nothing displayed and "Loading..." when actively asking for an autocomplete using ctrl + space.
I was on VSCode 1.25.1, an embeddable python 3.8.6, and the Python Extension 2018.7.1
In short, python 3.8 was not supported by the Python Extension 2018.7.1
While IntelliSense failed silently on VSCode, opening Help > Toggle Developer Tools > Console, I had this error:
Python Extension: stderr jediProxy, Error (stderr) Traceback (most recent call last):
File "d:\Users\user\.vscode\extensions\ms-python.python-2018.7.1\pythonFiles\parso\grammar.py", line 236, in load_grammar
return _loaded_grammars[path]
KeyError: 'd:\\Users\\user\\.vscode\\extensions\\ms-python.python-2018.7.1\\pythonFiles\\parso\\python\\grammar38.txt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\Users\user\.vscode\extensions\ms-python.python-2018.7.1\pythonFiles\parso\grammar.py", line 239, in load_grammar
with open(path) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'd:\\Users\\user\\.vscode\\extensions\\ms-python.python-2018.7.1\\pythonFiles\\parso\\python\\grammar38.txt'
Making a grammar38.txt copy of grammar37.txt is enough to fix IntelliSense in this case - to an extent. If possible, downgrading python or upgrading vscode would be better.

Related

MacOS: different treatment of IDEs and terminal when running code?

I am having a problem with a python IDE (Sublime) on macos when trying to use ktinter:
I set up a clean mac and installed Python 3.7 via the normal installer (with the box ticked to install tkinter)
The problem I am having now is this: When I write code in Sublime and try to run it within the IDE (Sublime -> Tools -> Build) I get an error message.
Code
import tkinter as tk
tk._test()
Output
Traceback (most recent call last):
File "/Users/christiankoch/Desktop/sys.py", line 1, in <module>
import tkinter as tk
ImportError: No module named tkinter
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/Users/christiankoch/Desktop/sys.py"]
[dir: /Users/christiankoch/Desktop]
[path: /Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]
However, when I just save the file and run it in the terminal everything works fine and I see the test window.
In the terminal
python3 test.py
So ultimately I am confused about different outcomes of the two approaches. When I use Sublime on Windows it works perfectly fine; and even using pyCharm on macos works for tkinter. So I am confused what the problem is.
When you run file.py from the console, the executable as specified in the environment variables is used by default.
In sublime you probably using a build system, that points to another environment/ executable. You should have a look at https://youtu.be/xqcTfplzr7c
And follow the instructions.

Run Visual Python script from bash terminal

I am trying to run the example programs that come with Visual Python ("VPython") like bounce.py, orbit.py, etc through bash.
When I'm in the folder which contains these examples (C:\Python27\Lib\site-packages\visual\examples), I can right-click on any of the examples and choose "open with" and then select "python.exe" from the list of given programs. This method is able to run the programs just fine and it generates the visual representation of a ball bouncing in a room, orbiting balls, etc.
On the other hand, when I use bash to navigate to this folder and then try to run python bounce.py, I get the error message:
Traceback (most recent call last): File "bounce.py", line 1, in
from visual import * ImportError: No module named visual
I was under the impression that calling python bounce.py was effectively the same as opening the file with the python executable but the behavior is different. I'm not sure why the "open with python.exe" method would allow the example to find the visual module but opening the example through bash is unable to find the same module. Any advice or help would be appreciated.
(Side note, I am running Bash on Ubuntu on Windows through the new beta https://msdn.microsoft.com/en-us/commandline/wsl/about)
The Linux environment (Bash on Windows) includes a builtin python, which does not have the package visual.
If you double-click the file, right-click and then open with python.exe, or execute the script via cmd or powershell, it will use the Python installed on the Windows machine. If you execute the script in bash, it will use the Python in Linux subsystem. That's it.

Configuring Pycharm to run Pyinstaller

Yes I want to create a run configuration in PyCharm to run Pyinstaller and get my executable. According to the Pyinstaller documentation you should be able to locate an python script called pyinstaller-folder/pyinstaller.py after the installation, but it wasn't there. Then I look carefully and found this other one named pyinstaller-folder/__main__.py which should be the same <--(me wild guessing), so I set up my running configuration like this:
After running it, is giving me this error:
/usr/local/Cellar/python3/3.4.3/bin/python3.4 /usr/local/lib/python3.4/sit
e-packages/PyInstaller/__main__.py --onefile --nowindow --osx-bundle-identifier=jg.optimizer -F --name=genoptimizer optimizer/manage.py
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/PyInstaller/__main__.py", line 26, in <module>
from . import __version__
SystemError: Parent module '' not loaded, cannot perform relative import
Process finished with exit code 1
It seems to require a parent module to run but, how would that look like?
After more than two years, perhaps there is a better option.
In the PyCharm menu go to File -> Settings.
In the Settings dialog find Tools -> External tools and use the green + to add a new external tool.
For example:
Then, the IDE will allow you to run it on any python script. Right click on the file and the context menu will show External tools -> PyInstaller.
The PyInstaller package is a runnable module and can be run using python -m PyInstaller. To configure it as a run target in PyCharm, leave the "Script" field blank, write -m PyInstaller in the "Interpreter Options" field, and put the PyInstaller parameters into the "Script Parameters" field.
For example:
PyCharm will complain that the "Script" field is empty, but it will let you run the configuration anyway.
The run command has changed a bit since the accepted answer. You can now select a module to launch rather than editing the interpreter options.
As of writing this answer, here is how it looks like:
Notes:
This solution requires to install PyInstaller in the virtual environment of the project.
I am using PyCharm pro 2020.1
Old solution should still work
Using external tool is still a possibility. Which solution you choose is a matter of personal preference.
Install pyinstaller in pycharm, then open the pycharm terminal and write python -m PyInstaller.
So as Pycharm has newly updates, my case was a bit different as I installed pyinstaller from the interpreter settings as the following picture shows:
For Linux Users:
You could install it in both Python 2.7 or Python 3.7+. Make sure to get the path of where pyinstaller was stored.Then in the Settings option, try to find Tools -> External tools and add a new external tool as the following picture shows:
For Windows users:
If you are using Pycharm or any virtual environment. Unfortunatelly Pycharm creates its local vertual environment in venvpath once you indicate the interpreter. So, you should set the external tool (pyinstaller) to the real path of your python 3.7 .exe as the picture shows
For those of us on Windows with Anaconda trying to figure this out, I found it easiest to just set up a Bash Configuration (I believe you need the BashSupport plugin for this), and set:
Script: pyinstaller (assuming pyinstaller is in your path, if not, the full path)
Interpreter path: C:\Windows\system32\cmd.exe (yes, a bash configuration can just use the standard command program)
Interpreter options: /C
Program arguments: script_name.py (along with any other pyinstaller arguments)
Working Directory: C:\Path\To\Script

DLL load failed: The specified procedure could not be found [duplicate]

I created python executables with py2exe with both 64bit python interpreter and 32 bit python interpreter.
In my program, I use the module pywin32 com, and so I dl'ed and installed both the 64bit and 32bit versions of the program prior to creating the executable.
The 64bit exe works fine, but the 32 bit one has the following problem:
Traceback (most recent call last):
File "program.py", line 11, in <module>
File "win32com\__init__.pyc", line 5, in <module>
File "win32api.pyc", line 12, in <module>
File "win32api.pyc", line 10, in __load
ImportError: DLL load failed: The specified procedure could not be found.
I tried both versions by running the source directly, ie python program.py and C:\python_32\python.exe program.py and both work fine.
Note I tested the 64bit exe on a 64bit windows 7 computer and the 32bit exe on a 32bit windows XP computer.
Older than everything ever, but I stumbled on this problem today, and if anyone else does, what I ran was:
python /c/Python26/Scripts/pywin32_postinstall.py -install from the commandline (change values to fit). That worked:
$ python /c/Python26/Scripts/pywin32_postinstall.py -install
Copied pythoncom26.dll to C:\WINDOWS\system32\pythoncom26.dll
Copied pythoncomloader26.dll to C:\WINDOWS\system32\pythoncomloader26.dll
Copied pywintypes26.dll to C:\WINDOWS\system32\pywintypes26.dll
Registered: Python.Interpreter
Registered: Python.Dictionary
Registered: Python
-> Software\Python\PythonCore\2.6\Help[None]=None
-> Software\Python\PythonCore\2.6\Help\PythonwinReference[None]='c:\\Python26\\Lib\\site-packages\\PyWin32.chm'
Pythonwin has been registered in context menu
Creating directory c:\Python26\Lib\site-packages\win32com\gen_py
Shortcut for Pythonwin created
Shortcut to documentation created
The pywin32 extensions were successfully installed.`
(On WinXP SP3)
Had the above noted errors with my python27 pywin32 installation that got installed after my installation of ArcGIS on a windows2008 R2 server (trying to centralize our scripts).
Found that for me, I had to start a command line window with run as adminstrator (right click to get that option in windows) and then run the following command line from the c:\arcpy27\arcgis10.1>python c:/arcpy27/arcgis10.1/scripts/pywin32_postinstall.py -install
I see a lot of people have run into this issue and I tried multiple things, but this was finally the solution that managed to get pywin32 installed.
Thanks so much for your solution. Took me a couple of install and uninstalls before I finally ran across your solution and modified it for my version.

dll load errors in python executable made from pywin32

I created python executables with py2exe with both 64bit python interpreter and 32 bit python interpreter.
In my program, I use the module pywin32 com, and so I dl'ed and installed both the 64bit and 32bit versions of the program prior to creating the executable.
The 64bit exe works fine, but the 32 bit one has the following problem:
Traceback (most recent call last):
File "program.py", line 11, in <module>
File "win32com\__init__.pyc", line 5, in <module>
File "win32api.pyc", line 12, in <module>
File "win32api.pyc", line 10, in __load
ImportError: DLL load failed: The specified procedure could not be found.
I tried both versions by running the source directly, ie python program.py and C:\python_32\python.exe program.py and both work fine.
Note I tested the 64bit exe on a 64bit windows 7 computer and the 32bit exe on a 32bit windows XP computer.
Older than everything ever, but I stumbled on this problem today, and if anyone else does, what I ran was:
python /c/Python26/Scripts/pywin32_postinstall.py -install from the commandline (change values to fit). That worked:
$ python /c/Python26/Scripts/pywin32_postinstall.py -install
Copied pythoncom26.dll to C:\WINDOWS\system32\pythoncom26.dll
Copied pythoncomloader26.dll to C:\WINDOWS\system32\pythoncomloader26.dll
Copied pywintypes26.dll to C:\WINDOWS\system32\pywintypes26.dll
Registered: Python.Interpreter
Registered: Python.Dictionary
Registered: Python
-> Software\Python\PythonCore\2.6\Help[None]=None
-> Software\Python\PythonCore\2.6\Help\PythonwinReference[None]='c:\\Python26\\Lib\\site-packages\\PyWin32.chm'
Pythonwin has been registered in context menu
Creating directory c:\Python26\Lib\site-packages\win32com\gen_py
Shortcut for Pythonwin created
Shortcut to documentation created
The pywin32 extensions were successfully installed.`
(On WinXP SP3)
Had the above noted errors with my python27 pywin32 installation that got installed after my installation of ArcGIS on a windows2008 R2 server (trying to centralize our scripts).
Found that for me, I had to start a command line window with run as adminstrator (right click to get that option in windows) and then run the following command line from the c:\arcpy27\arcgis10.1>python c:/arcpy27/arcgis10.1/scripts/pywin32_postinstall.py -install
I see a lot of people have run into this issue and I tried multiple things, but this was finally the solution that managed to get pywin32 installed.
Thanks so much for your solution. Took me a couple of install and uninstalls before I finally ran across your solution and modified it for my version.

Categories

Resources