Summary of problems encountered when eclispe imports external Python files


First, create a new project and click pydev project.

The second step, name the project name, at the bottom choose to add the project name to PYTHONPAYH, click Finish, then the project is created successfully.


Next, we can directly import our own Python files, but there are several options: first, import the file directly; second, by creating a pydev packge;

the first method:

First, directly import the file, right-click on the corresponding project name cifar_test, new->other->General->Folder, then click next, then click Advanced, select the bottom link to the file. Or new->Folder->Advanced.....


Click Browse, you can choose the location where your Python code is stored in my computer, and finish after selecting it.


The results show that it can run normally, and there is no need to build an additional __init__.py file. Before I did not build __init__.py through the following two methods, my project and code appeared red crosses and yellow exclamation marks, but But it can run normally. It turns out that I did not add the project path to the Python path. This is the third one I chose at the time. I wanted to directly import external files by creating a project.


The second method:

Also right-click cifar_test and select new->pydev package, go in and name the package, I am test


As you can see, it will automatically add the _init_.py file under the package, and then import your own Python code file under this package. The method is the same as above new->other->General->Folder, then click next, then click Advanced, Check the bottom link to file.


normal operation.

Finally, a graph of the running results without optimization is attached. In addition, the directory where the Python file selected on the computer is located, and the eclipse workspace do not need to add additional PYTHONPATH, because the project was created in the early stage. It has been automatically added internally.



Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326925502&siteId=291194637