0

I have a Pycharm project where I have copied two github projects (download zip and copy paste into project). My problem is that I cannot access the from main, which is located at root.

For some unknown reason from . syntax only shows me files/folders I have created myself.

I'm trying to access build module where there is a class TFNET which I want to import

from darkflow-master.darkflow.net.build import TFNET

Screenshot1

Screenshot2

Screenshot3

normanius
  • 8,629
  • 7
  • 53
  • 83

2 Answers2

0

Downloading directories like this isn't how you'd typically include external dependencies in a python project.

A more conventional approaches would be ot install the project using pip, it looks like darkflow gives information on how to do this.

Alternatively, just ensure the libraries are in your PYTHONPATH, it looks like pycharm has a way to do this: PyCharm and PYTHONPATH

Sam Broster
  • 542
  • 5
  • 15
  • Thank you for the reply. I'm very new to python and with project structures. I had trouble with the pip install so I thought I would try to just download the package and go from there. I couldn't understand what to do. What are Cython extensions and how do I use them? However I followed the python path instructions right-click any folder in your project select "Mark Directory As" select "Sources Root" I marked the darkflow-master as Sources root, but it still not working. https://imgur.com/a/lOshmNU – PythonBeginner__ Jan 19 '20 at 13:27
  • It'll definitely be worth your while learning how to use pip but if you want to get the subdirectories working please can you include information about the contents of the `darkflow-master` and `labellmg-master` directories. – Sam Broster Jan 19 '20 at 14:10
  • Somehow I managed to get this to work. Any tips where I could learn how to use pip better? – PythonBeginner__ Jan 19 '20 at 15:55
0

Reading between the lines, it sounds like you have downloaded two libraries from github, and copied them into your project.

Python needs to know where to find source files.

If you want do it this way, you need to tell your python environment where to find the new sources. Pycharm looks after python environments while you are in python.

Please see https://www.jetbrains.com/help/pycharm/configuring-folders-within-a-content-root.html

but this won't tell python outside of Pycharm where to find your library source.

pip is most likely the answer. pip can install globally or inside python virtual environments, in either case, it puts the library code in a location python is expecting to find it.

On this point, please learn about python virtual environments. These are self-contained python mini-worlds. In a venv, you can run a specific version of python with specific packages. Pycharm works well with them, it is easy to set up virtual envs with pycharm. When you are 'inside' a venv, pip will install into the venv, therefore not touching your system python or the python of any other projects.

Also, pip normally installs from an official repository (pypi) but you can tell it to use a git repository as the source of your install. Normally people who write libraries send their mature versions to pypi so it is unusual to fetch from a git repository, but if you want the very latest version, or if the author has not published the library, it's an option.

Note that pip doesn't work with any arbitrary python code. It must be set up to be seen by pip as a python package.

Tim Richardson
  • 6,608
  • 6
  • 44
  • 71