Python Forum
Appending sys.path not working with spyder
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Appending sys.path not working with spyder
#1
After many years of using VSCode, I am experimenting with using Spyder as my IDE, fed up with VSCode telemetry which occurs even though 'turned off'.

OS: Linux Mint 21.3

The following code using VSCode has always found the included module CCpaths
It also works if I execute from command line.

However this does not work with spyder, which gives me a 'module not found' error, and seems to ignore sys.path

The CommandProcessor
my path is as follows:

CommandProcessorProject
.
├── data
├── doc
├── requirements.txt
├── src
│     ├── common
│     │     ├── CCpaths.py
│     │     ├── images
│     │     │     ├── ...
│     │     ├── __init__.py
│     │── core
│     │    ├── CommandProcessor.py
│     │    └── __init__.py
├── venv
├── ...
import sys
sys.path.append("./src/common")

from CCpaths import CCpaths


class CommandProcessor:
    def __init__(self):
        self.cpath = CCpaths(depth=1)
        ...
I am stumbling through the setup of Spyder, and doing OK, but this one is frustrating me.
Reply
#2
If this sys.path update produces no effect, it could mean that the current directory at run time is not the one containing src. Assuming that this code is in CommandProcessor.py, you could try
from pathlib import Path
here = Path(__file__).parent  # this is the 'core' directory
sys.path.append(str(here.parent/'common'))
Larz60+ likes this post
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
Quote:here = Path(__file__).parent # this is the 'core' directory
That's too much common sense
When frustrated, I don't have any common sense.
I'll give it a go.

--- EDIT 5:01 A.M. EDT ---
Gribouillis ... That worked like a champ
What I had been using (for years) has always worked before, but never tested with other IDE's
Your method is more sure, and should work for most (if not all) environments.
Thank You
Gribouillis likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Appending lists into lists from function is not working for me BoredBannana 2 1,162 Oct-25-2024, 05:18 PM
Last Post: deanhystad
  Spyder console zoom in not working? Dionysis 2 1,558 Feb-06-2024, 03:31 PM
Last Post: paul18fr
  working directory if using windows path-variable chitarup 2 1,478 Nov-28-2023, 11:36 PM
Last Post: chitarup
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 3,156 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  Subprocess.Popen() not working when reading file path from csv file herwin 13 24,043 May-07-2021, 03:26 PM
Last Post: herwin
  Spyder stopped working in Windows 10 gammaray 3 4,296 Apr-19-2021, 05:33 PM
Last Post: jefsummers
  Appending to list not working and causing a infinite loop eiger23 8 6,175 Oct-10-2019, 03:41 PM
Last Post: eiger23
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 7,529 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908
  Problem in a path finding algorithm (counter is not working) Kowalski 3 4,011 Feb-05-2018, 01:23 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020