1

Recently I started working on a project with other people. Part of the project is made on Python, and when I try executing it I get the following error:

File "D:\projects\company\spiders\country\spain\cities\runnables\short.py", line 22, in <module>
    soup = get_soup_from_url(url, "html.parser")
NameError: name 'get_soup_from_url' is not defined

After talking with some of my partners, it looks like I am the only one getting this error, the code works for everyone else except for me. Having this in count I guess is a problem with my Visual Studio Code, since we all work with editor and on Windows 10.

I made a small, simple project where I get this same error with two small scripts, the project follows this structure:

- spiders
   - country
      - spain
         - cities
            - runnable
               - short.py
   - utils
      - driver.py

And the scripts are the following:

short.py

import sys

sys.path.append('../../../../utils')

from driver import *

print_on_console('Hello world!')

driver.py

def print_on_console(message):
    print(message)

So basically I get this error when trying to import the function "print_on_console" into short.py.

I don't know if it is necessary but this is my settings.json form Visual Studio Code:

{
  "terminal.integrated.tabs.enabled": true,
  "security.workspace.trust.untrustedFiles": "open",
  "editor.fontSize": 18,
  "workbench.colorTheme": "Oceanic Next (dimmed bg)",
  "tabnine.experimentalAutoImports": true,
  "editor.guides.bracketPairs": true,
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "terminal.integrated.profiles.windows": {
    "PowerShell": {
      "source": "PowerShell",
      "icon": "terminal-powershell"
    },
    "Command Prompt": {
      "path": [
        "${env:windir}\\Sysnative\\cmd.exe",
        "${env:windir}\\System32\\cmd.exe"
      ],
      "args": [],
      "icon": "terminal-cmd"
    },
    "Git Bash": {
      "source": "Git Bash"
    },
    "Ubuntu-20.04 (WSL)": {
      "path": "C:\\Windows\\System32\\wsl.exe",
      "args": ["-d", "Ubuntu-20.04"]
    },
    "Ubuntu (WSL)": {
      "path": "C:\\Windows\\System32\\wsl.exe",
      "args": ["-d", "Ubuntu"]
    }
  },
  "terminal.integrated.defaultProfile.windows": "PowerShell"
}

As extensions, the related to Python ones that I am currently using are:

  • Jupyter
  • Jupyter Keymap
  • Jupyter Notebook Renderers
  • Pylance
  • Python

Thanks in advance to anyone who tries to help me with this issue!

4
  • Although the code you provided has nothing to do with the error content, I can remind you that vscode is retrieved based on the workspace, not the current file, so '../../../utils' is invalid, try "./utils" if your workspace is spiders. Commented Sep 20, 2022 at 1:26
  • Hi @MingJie-MSFT, I use runnables as workspace when executing the script, although what you say is correct, the main project that works the same as the code I posted works fine for my partners, so I think that's not the problem Commented Sep 20, 2022 at 6:45
  • Do they also use vscode editing? Is the choice of workspace the same? By the way, you can improve the problem because the error content is inconsistent with the code you provided. Commented Sep 20, 2022 at 6:56
  • Yes, we all use vscode for editing and we all run the script from runnables. The code I provided gives me the error, but I understand you are not getting the error from it since it probably works fine for you Commented Sep 20, 2022 at 7:30

1 Answer 1

1

Are you running in a venv or do you have the packages installed globally? If you are running in a venv you probably need to add the venv path in VS Code

enter image description here

Select this in the bottom right corner of VS Code then

enter image description here

Select Enter Interpreter path and select the location of the python.exe file from your venv Then if you run via VS Code it will launch into the venv automatically

Sign up to request clarification or add additional context in comments.

2 Comments

Hi @Cornelius-Figgle, when you say "do you have the packages installed globally" you mean the extensions? For the interpreter stuff here's a screenshot with what I'm currently using, I don't know if I'm using the correct one image
No I meant the modules - Your sample code appears to use BeautifulSoup, which is a module installed from pip (probably). If you installed them into a virtual environment then you need to launch the script in the virtual environment, if not then maybe check it has been saved globally?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.