I am using PyCharm as an editor for python code in Houdini. Whenever I try to import the main Houdini library (hou) I get an error flagged in PyCharm. If I include the code snippet:-
try: import hou except ImportError: # Add $HFS/houdini/python2.6libs to sys.path so Python can find the # hou module. sys.path.append(os.environ['HFS'] + "/houdini/python%d.%dlibs" % sys.version_info[:2]) import hou
my code executes, without problem, from both Houdini and my selected interpreter.
My problem is with PyCharm itself. The editor flags 'import hou' as an error and any subsequent files that import this file flag modules imported by this file as errors as well. Hence I loose type ahead functionality and get an over abundance of error messages that make it hard to spot the real problems.
How do I get PyCharm to recognize the path to the hou module.
I have tried, for a couple of days, to Google a solution to this problem but they all seem to refer to tabs and settings that are not in my version of PyCharm (Community Edition 3.4.1). E.G. my 'Project Interpreter' setting only has a list of Packages and has no 'path' tab as stated in many 'fixes' to closely related problems.
PyCharm can do both. Type the name of the package and hit Alt-Enter , then choose Install and Import package . PyCharm will do both: you'll see a notification during the installation, then the import will be generated in the right way, according to your project styles.
Since PyCharm 3.4 the path tab in the 'Project Interpreter' settings has been replaced. In order to add paths to a project you need to select the cogwheel, click on 'More...' and then select the "Show path for the selected interpreter" icon. This allows you to add paths to your project as before.
My project is now behaving as I would expect.
Answer for PyCharm 2016.1 on OSX: (This is an update to the answer by @GeorgeWilliams993's answer above, but I don't have the rep yet to make comments.)
Go to Pycharm menu --> Preferences --> Project: (projectname) --> Project Interpreter
At the top is a popup for "Project Interpreter," and to the right of it is a button with ellipses (...) - click on this button for a different popup and choose "More" (or, as it turns out, click on the main popup and choose "Show All").
This shows a list of interpreters, with one selected. At the bottom of the screen are a set of tools... pick the rightmost one:
Now you should see all the paths pycharm is searching to find imports, and you can use the "+" button at the bottom to add a new path.
I think the most significant difference from @GeorgeWilliams993's answer is that the gear button has been replaced by a set of ellipses. That threw me off.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With