In PyCharm, I've added the Python environment /usr/bin/python
. However,
from gnuradio import gr
fails as an undefined reference. However, it works fine in the Python interpreter from the command line.
GNURadio works fine with python outside of Pycharm. Everything is installed and configured how I want it.
Gnuradio is located at /usr/local/lib/python2.7/site-packages/gnuradio
Also:
PYTHONPATH=/usr/local/lib/python2.7/site-packages:/usr/local/lib/python2.7/site-packages/gnuradio
Download anaconda https://anaconda.org/
once done installing anaconda...
Go into Settings -> Project Settings -> Project Interpreter.
Then navigate to the "Paths" tab and search for /anaconda/bin/python
click apply
For me, it was just a matter of marking the directory as a source root.
On Project Explorer, you can right click on the folder where the module is contained and set as 'Source'.
It will be parsed in the Index for code completion as well as other items.
Add path in PyCharm 2017
File -> Settings (or Ctrl+Alt+S) -> Project -> Project Interpreter
Show all
Select bottom icon on the right side
Click on the plus button to add new path to your module
Adding a Path
Go into File → Settings → Project Settings → Project Interpreter.
Then press configure interpreter, and navigate to the "Paths" tab.
Press the + button in the Paths area. You can put the path to the module you'd like it to recognize.
But I don't know the path..
Open the python interpreter where you can import the module.
Most commonly you'll have a folder structure like this:
You want to add foobarbaz to the path here.
You should never need to modify the path directly, either through environment variables or
sys.path
. Whether you use the os (ex.apt-get
), orpip
in a virtualenv, packages will be installed to a location already on the path.In your example, GNU Radio is installed to the system Python 2's standard
site-packages
location, which is already in the path. Pointing PyCharm at the correct interpreter is enough; if it isn't there is something else wrong that isn't apparent. It may be that/usr/bin/python
does not point to the same interpreter that GNU Radio was installed in; try pointing specifically at thepython2.7
binary. Or, PyCharm used to be somewhat bad at detecting packages;File > Invalidate Caches > Invalidate and Restart
would tell it to rescan.This answer will cover how you should set up a project environment, install packages in different scenarios, and configure PyCharm. I refer multiple times to the Python Packaging User Guide, written by the same group that maintains the official Python packaging tools.
The correct way to develop a Python application is with a virtualenv. Packages and version are installed without effecting the system or other projects. PyCharm has a built-in interface to create a virtualenv and install packages. Or you can create it from the command line and then point PyCharm at it.
In your PyCharm project, go to
File > Settings > Project > Project Interpreter
. If you usedvirtualenvwrapper
or PyCharm to create the env, then it should show up in the menu. If not, click the gear, chooseAdd Local
, and locate the Python binary in the env. PyCharm will display all the packages in the selected env.In some cases, such as with GNU Radio, there is no package to install with
pip
, the package was installed system-wide when you install the rest of GNU Radio (ex.apt-get install gnuradio
). In this case, you should still use a virtualenv, but you'll need to make it aware of this system package.Unfortunately it looks a little messy, because all system packages will now appear in your env, but they are just links, you can still safely install or upgrade packages without effecting the system.
In some cases, you will have multiple local packages you're developing, and will want one project to use the other package. In this case you might think you have to add the local package to the other project's path, but this is not the case. You should install your package in development mode. All this requires is adding a
setup.py
file to your package, which will be required anyway to properly distribute and deploy the package later.Minimal
setup.py
for your first project:Then install it in your second project's env: