VSCode / Pylint question

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

VSCode / Pylint question

Post by Joel_graff »

Ok, so I recently got into using VSCode for a Unity3D C# scripting project. I really like it.

So, I'm trying to get it set up for python scripting in FreeCAD just to do general development. A minor housekeeping issue has arose, though. VSCode / pylint can't find the FreeCAD modules I regularly import (FreeCAD, FreeCADGui, Part, etc.) It's a minor issue since I'm not running the code from VSCode, but I've made a few attempts at resolving it with no luck.

Any thoughts?
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: VSCode / Pylint question

Post by triplus »

Joel_graff wrote: Sun Jan 21, 2018 11:56 am It's a minor issue since I'm not running the code from VSCode, but I've made a few attempts at resolving it with no luck.

Any thoughts?
I assume you use Linux (Ubuntu)? One way is to add (locate FreeCAD.so):

Code: Select all

init-hook='import sys; sys.path.append("/usr/lib/freecad/lib")'
Inside .pylintrc (located in home directory). If by any chance VSCode isn't using the .pylintrc and has its own settings. Look here for clues:

https://github.com/Microsoft/vscode-python/issues/179
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: VSCode / Pylint question

Post by Joel_graff »

triplus wrote: Sun Jan 21, 2018 1:11 pm I assume you use Linux (Ubuntu)? One way is to add (locate FreeCAD.so):

Code: Select all

init-hook='import sys; sys.path.append("/usr/lib/freecad/lib")'

Inside .pylintrc (located in home directory).
Worked like a charm! Thanks!
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: VSCode / Pylint question

Post by triplus »

Joel_graff wrote: Sun Jan 21, 2018 1:50 pm Worked like a charm! Thanks!
Good to hear that and you're welcome.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: VSCode / Pylint question

Post by Kunda1 »

Joel_graff wrote: Sun Jan 21, 2018 1:50 pm
triplus wrote: Sun Jan 21, 2018 1:11 pm I assume you use Linux (Ubuntu)? One way is to add (locate FreeCAD.so):

Code: Select all

init-hook='import sys; sys.path.append("/usr/lib/freecad/lib")'

Inside .pylintrc (located in home directory).
Worked like a charm! Thanks!
Where can we document this on the wiki? (It just may be already but I didn't see it?)
Specifically, a page to help people set up vscode for FreeCAD development
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
wallison
Posts: 3
Joined: Sat May 16, 2020 12:51 am

Re: VSCode / Pylint question

Post by wallison »

Kunda1 wrote: Fri Sep 20, 2019 7:10 pm
Joel_graff wrote: Sun Jan 21, 2018 1:50 pm
triplus wrote: Sun Jan 21, 2018 1:11 pm I assume you use Linux (Ubuntu)? One way is to add (locate FreeCAD.so):

Code: Select all

init-hook='import sys; sys.path.append("/usr/lib/freecad/lib")'

Inside .pylintrc (located in home directory).
Worked like a charm! Thanks!
Where can we document this on the wiki? (It just may be already but I didn't see it?)
Specifically, a page to help people set up vscode for FreeCAD development
I also need help with that!
User avatar
prandall
Posts: 76
Joined: Thu Feb 16, 2017 12:42 pm
Contact:

Re: VSCode / Pylint question

Post by prandall »

.pylintrc does not seem to located in my home directory.

To add it, I changed to my project folder:
~/.FreeCAD/Mods/workbench/.pylintrc


I had to generate the .pylintrc using:

pylintrc --generate-rcfile > .pylintrc


In the .initrc, I found an init-hook section

Code: Select all


[MASTER]
...

# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=

init-hook='import sys; sys.path.append("/usr/lib/freecad/lib")'
3D Printing, CAD, Electronics and other errata at: https://www.youtube.com/channel/mathcodeprint
Post Reply