i have import simplejson in my code, and installed using pip install simplejson using python3
so as i checked, it perfectly runs in my terminal opening the file but when i try to build in VScode, it shows an error like,
see the error in this link as
`> Executing task: python /Users/Tony/Documents/python3.9/helloworld.py <
Traceback (most recent call last):
File "/Users/Tony/Documents/python3.9/helloworld.py", line 1, in
import simplejson as json
ImportError: No module named simplejson
The terminal process "/bin/bash '-c', 'python /Users/Tony/Documents/python3.9/helloworld.py'" failed to launch (exit code: 1).
but it still runs on my terminal. and if i check the pip list, simplejson is still there and i also tried to use different version of python too.
and I have activated the virtual environment enter image description here
and i am using the last one which i recently activated.
please help me to find the error. i don’t really know where to fix thanks
I've reproduced this process and hope the following steps could help you
1.Activate the venv and install simplejson;
2.Run the helloworld.py in Terminal to make sure the script no error;
3.Configure the tasks.json, pay attention to use the venv's pythonpath;
"version": "2.0.0",
"tasks": [
{
"label": "run python file",
"type": "shell",
"command": "/venv's pythonpath/ helloworld.py",
"group": {
"kind": "test",
"isDefault": true
},
"problemMatcher": [
"$tsc"
]
}
]
4.Tasks:Run Task;
Related
[{
"resource": "/d:/Users/Home/Desktop/Python/estudos/pratices.py",
"owner": "_generated_diagnostic_collection_name_#0",
"code": {
"value": "reportMissingModuleSource",
"target": {
"$mid": 1,
"external": "https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportMissingModuleSource",
"path": "/microsoft/pyright/blob/main/docs/configuration.md",
"scheme": "https",
"authority": "github.com",
"fragment": "reportMissingModuleSource"
}
},
"severity": 4,
"message": "Import \"pandas\" could not be resolved from source",
"source": "Pylance",
"startLineNumber": 1,
"startColumn": 8,
"endLineNumber": 1,
"endColumn": 14
}]
is the message given
the cmd shell tells me i have all the libraries i want installed and they're in the project folder, i'm running a virtual environment but whenever i try to run something in a .py file, it says that it's not defined, i have installed anaconda but don't mean to use it right now, if i open a jupyter file it'll import no problem, but trying to run pip doesn't work at all
reinstalling vscode, making sure python's installed, making sure pip is installed
I had a similar issue before and the solution I found is that you have to make sure the python interpreter for the current VSC window is your virtual environment instead of the system-wide python interpreter. On windows:
Press F1
Search for "interpreter".
Click the python one
Click "Enter interpreter path".
Finally locate your virtual environment.
You should make sure that the current interpreter and the pandas library installed are the same interpreter environment.
The current interpreter can be output with the following code.
import sys
print(sys.executable)
Then install the pandas library with the resulting interpreter path.
<the path obtained above> -m pip install pandas
I am a beginner with python, I am working on this project using a module named classy-classification. I pip-installed it and checked if it was actually correctly installed where it should be, and tried to install it manually, but I am still getting the same ModuleNotFoundError error.
import spacy
import classy_classification
data = {
"furniture": ["This text is about chairs.",
"Couches, benches and televisions.",
"I really need to get a new sofa."],
"kitchen": ["There also exist things like fridges.",
"I hope to be getting a new stove today.",
"Do you also have some ovens."]
}
nlp = spacy.load("en_core_web_md")
nlp.add_pipe(
"text_categorizer",
config={
"data": data,
"model": "spacy"
}
)
print(nlp("I am looking for kitchen appliances.")._.cats)
The error:
C:\Users\BC\PycharmProjects\pythonai\venv\Scripts\python.exe C:/Users/BC/PycharmProjects/pythonai/main.py
Traceback (most recent call last):
File "C:\Users\BC\PycharmProjects\pythonai\main.py", line 2, in <module>
import classy_classification
ModuleNotFoundError: No module named 'classy_classification'
Process finished with exit code 1
Sometimes, if you have multiple versions of Python installed and/or multiple environments, it can be a bit tricky to install packages. It looks like your code is running using the Python interpreter located at C:\Users\BC\PycharmProjects\pythonai\venv\Scripts\python.exe.
So, try using the following command to install classy_classification: C:\Users\BC\PycharmProjects\pythonai\venv\Scripts\python.exe -m pip install classy_classification.
In general, instead of running pip [args], you can run /path/to/python -m pip [args] to specify the Python version/interpreter that pip installs packages for.
I am building an application in Python. A while ago, I was able to debug it without any issues, but after accidently reseting my VS Code settings, I am not able anymore. Whenever I try to debug I get the following error on the first installed library I try to import:
Exception has occurred: ModuleNotFoundError No module named
'PySimpleGUI'
When I try to install the library using pip3, I get the message:
Requirement already satisfied: PySimpleGui in c:\users\adassa\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages
When I run directly from the console using python3 name_of_file.py, the file runs without any problems. Here is my launch.json for debugging:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env": { "PYTHONPATH": "${workspaceRoot}"}
}
]
}
I read in other questions that this error has to do with different installations of Python, and the debugger trying to find the library on the wrong directory, but couldn't understand how to solve it.
I tried replacing PYTHONPATH with the path of python3 I get from the console. (I obtaineed that path using the command from this answer: https://stackoverflow.com/a/647798/14874778, but the error remains. How can I solve this problem?
Do you have multiple python installations? If so, try something that looks like this (made for python 3.7.9 & Windows):
py -3.7 -m pip install pysimplegui
This has always worked for me.
You can also try specifying which installation you want to run the script, which should look like this (also 3.7.9, also Windows):
py -3.7 helloworld.py
I am learning how to create GTK applications in python and I am using Gnome Builder IDE installed through flatpak.
I wanted to use the python package requests in my application, so I added:
{
"name": "pip-install",
"buildsystem": "simple",
"build-options": {
"build-args": [
"--share=network"
]
},
"build-commands": [
"pip3 install requests"
]
}
To my modules list inside the flatpak .json file of the project.
When I try to build the project I get the following error when the command runs pip:
ERROR: Could not install packages due to an EnvironmentError: [Errno 30] Read-only file system: '/usr/lib/python3.7/site-packages/idna-2.9.dist-info'
One solution would be the dependency being installed on user space, but how to do that?
I've successfully used this snippet before:
{
"name": "requests",
"buildsystem": "simple",
"build-options": {
"build-args": [
"--share=network"
]
},
"build-commands": [
"pip3 install --prefix=/app --no-cache-dir requests"
]
}
The /app directory is writable and the rest of your application should be there as well.
**********New post edition with a simple example********************
After the suggestion of Martineau, I tried a simplified example python program in the following.
The background was that last week Vscode asked me to update to VSCodeUserSetup-x64-1.31.1 in Win10.
So I did.
Then sometimes VSCode failed to execute my main module.
I tried to reinstall and uninstall vscode. I also tried to modify the path variables here and there.
But the problem is still there.
Still I can execute the program OK purely in the console.
The simplified python program is the following.
print ("Here I am!")
The launch.json file is the following.
{
"version": "0.2.0",
"configurations": [
{
"name": "vsCode Test ",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceRoot}/src/pt.py",
"args": [
],
"cwd": "${workspaceRoot}",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
}
]
}
After I clicked the debugger button and then the right triangle button to execute the debugger, I always got the following screenshot which showed that nothing was executed.
I suspect that the new update has changed my settings in vscode.
But I don't know where to reconfig vscode.
Your help will be deeply appreciated!
Thanks
Farn
****************Old post with a more complicate example!****************
dear all:
Last week Vscode asked me to update to VSCodeUserSetup-x64-1.31.1.
So I did.
Then sometimes VSCode stopped to execute my main module.
The basic screen layout is the following.
VSCode basically stalled before the first statement and the first breakpoint.
But if I use Console to execute "python CnTaaD.py -L", the module (CnTaaD.py) executed correctly.
I tried several times and even reinstall, uninstall, used an older version of VSCode.
The stalling problem came on and off.
Then last night, VSCode always stalled before the first statement and the first breakpoint.
My friend helped me and guessed it is because the path to python interpreter is wrong now.
But we tried to set the path variables here and there.
Nothing good happened.
The code of CnTaaD.py is in the following for your reference.
It calls another module.
Can anyone help by telling me how to reconfigure maybe VSCode so that I can resume the development ?
Thanks
from __future__ import print_function # (at top of module)
if __name__ == '__main__':
import os
import sys
import CnUserManager
if sys.version_info[0] < 3: # Python 2 and 3:
print ("python 2.x")
# to execute the file, type in the following command in powershell:
# % python CnTaaDPackage.py build_ext --inplace
import future # pip install future
import builtins # pip install future
import past # pip install future
import six # pip install six
else:
print ("python 3.x")
root = os.path.realpath(__file__)
# print ("realpath of __file__ is ", root)
root = os.path.dirname(root)
root = os.path.dirname(root)
sys.argv.append(root)
# print ("sys.argv = ", sys.argv)
CnUserManager.CnUserManagerClass(sys.argv)
I kind of solved the problem.
Basically, I removed the "RedirectOutput" option from the "debugOptions" in launch.json. Somehow, the older version the redirection is to the console in the debug screen.
But now I am not sure where it is to.
In fact, there are three consoles in VSCode, internal, integrated, and external.
I will appreciate it if someone can enlighten me which is which ?
I checked some related pages. But vague explanations are found.