PyDev - Importing relative to project root name - pydev

Say I have a project named "abcproject". Is there any way to import like so in PyDev?
from abcproject.core.page import Page
from abcproject import util
As opposed to this, which works perfectly:
from core.page import Page
import util
If I add my project folder to my PYTHONPATH it will vaguely work, but PyDev will treat the imports as external and doesn't seem to update them properly as things change, which gets really messy.

Definitely.
The problem is that you have to set as a source folder the folder containing the 'abcproject' and not the 'abcproject' itself.
I.e.:
You need a structure such as:
/my_project
/abcproject
__init__.py
/core
And /my_project must be set as the source folder (in project properties > PyDev - PYTHONPATH > Source folders).

Related

How to run a GO project in eclipse with goclipse installed

I have installed goclipse in my eclipse and created a new go project.
Now this is what I have:
And I have hello.go looks like this:
package main
import "fmt"
func main() {
fmt.Println("Hello")
}
Then I press run button, or right click the file hello.go, and then run, it gives nothing. Besides, it is also empty in bin folder.
Then I press run configurations button, almost empty there with only a project name. it gives:
Given Go package not found.
This is my Preferences for Go:
I noticed that both GOROOT and GOPATH are different from those listed in explorer, but once I changed them to C:\Go\src\pkg or C:\Go\src, the Apply and OK button becomes disabled. Besides, I don't have C:\Go\src\pkg folder either.
I can go install or go build in command line, but I would like to use eclipse for another much larger project. It's windows 7, and the eclipse version is Luna Service Release 1 (4.4.1). Thank you.
EDIT: Now I have the following configurations, and it works fine:
Go is installed at c:\Go
in Preferences: GOROOT:C:\Go, GOPATH: C:\Users\Tiina\go_workspace
The rest in Preferences is filled in automatically.
helloTest project is located at C:\Users\Tiina\go_workspace\src\helloTest
hello.go is located at C:\Users\Tiina\go_workspace\src\helloTest\hello.go
Maybe because I create a project from existing code, and there was something left behind, it automatically adds another GOPATH, in Preferences delete it.
If GOROOT refers to where go is installed (C:\Go), then you need to make sure that:
GOPATH differs from GOROOT (it is important, because GOROOT/[src|pkg|bin] are folders for the Go language itself, not for your own sources)
GOPPATH points to a folder under which all your different Go project will reside (for instance C:\Users\yourName\Go: that defines a workspace)
your eclipse project is created in GOPATH\src\myproject
See "How to Write Go Code" to make sure that your installation and project sources respect the expected organization.
The OP Tiina reports in the comments:
Now it works, but I noticed two things odd.
First what I did: I move helloTest folder into C:\Users\Tiina\go_workspace\src, so now it is at C:\Users\Tiina\go_workspace\src\helloTest.
Then I create project from existing code. Nothing else changed. Now I have two GOPATH in explorer, one is C:\Users\Tiina\go_workspace\src, the other one is C:\Users\Tiina\go_workspace\helloTest\src.
The latter one did no exist at the beginning
I suspect what goclipse does is define one GOPATH per project (or complete the existing GOPATH).
If you create or import a project, it will define/complete GOPATH in <that project/src>
If you hello.go is within that <that project/src/> folder, then it should build and work as expected.
The user guide "project structure" of goclipse mentions:
The project location is not part of any GOPATH entry.
In this case the project location will implicitly be added as an entry to the GOPATH, and a Go workspace structure with the bin, pkg, and src directories will be used in the project.
Note that the project's implicit GOPATH entry will only apply to the source modules in that project. It will not be visible to other Goclipse projects (unless the entry is explicitly added to the global GOPATH).
In the src folder you can create Go source files that will be compiled into a library package (and placed into pkg), or into an executable (and placed in bin)
Here's what one needs to do. One must always follow GO's convention of the directory structure. In eclipse, once a new project is created just create a "new folder" under the src directory by right clicking on the src folder. And now underneath this folder create a new GO file. I had issues running this on my MAC but by following the above steps was able to resolve.
Vishal (www.vishalpandya.com)
Please respect the fact, that if you change GOPATH while working in Eclise/GoClipse, you will have to Quit/restart Eclipse in order to Eclipse have the new environment variables to be reread.

How to import a package from a linked folder resource in a Flash Builder project?

I have this folder structure:
/source/MapEditor where the main project resides. (with its src folder inside)
/source/Geonerd with some classes declared as belonging to the Geonerd package.
I've tried to include the Geonerd package, with no luck.
How do I import it? ( the yellow warning icon says Definition Geonerd.Polygon could not be found )
If I copy the Geonerd folder instead, inside the src folder, I can do import Geonerd.* correctly, but not with the linked folder.
Note: it's not a .swc library, it's just the .as sources inside a folder all within the Geonerd package.
Note 2: I added the folder to the project's ActionScript Build Source Path but doesn't work either:
Note that what should be the Geonerd Package is recognized as (default package)
Update: if I make the linked sources belong to the anonymous package, I can import them, but the problem is they have to be in their own package to avoid name clash with other libraries I'm using. And that libraries in turn are also in their own package and I need to import them as well.
You need to add it as an external folder.
Select Project -> Properties -> ActionScript Build Path. On the build path properties page, select the Source Path tab. Click the Add Folder button. Enter or browse to the folder, click OK. The folder is added to the source path.
Should look similar to: http://blogs.adobe.com/airodynamics/files/2012/05/snapshot1.png
Actually I had to add a folder that had a folder inside, named Geonerd so then Flash Builder recognizes it as the Package Geonerd and not just a default package.

Eclipse Package Declaration Work Around?

The team in which I'm working doesn't use eclipse and wants the src folder to be setup a certain way. I, on the other hand, am using eclipse. They would like the src folder to have, for example, the following structure: src/main/java/com/* However, they would like package declarations to only have com.* in them. If I go to project->properties and in the source tab remove the src folder as a source folder and then _only add the com.* folder as part of the source_ it will show com.* as a package, but I still have to add the whole path from src down in the .java files. Here's an example of what I have to do in order for eclipse to recognize the packages:
package main.java.com.parser;
And what the team wants is to have main and java just be a folder so the package declaration would just be:
package com.parser;
So although the file structure would still be src/main/java/com/parser, the package name would be as stated in the later example.
Is there a way to do this in eclipse? I've seen some people asking similar questions on here, but they seem to have no concern that the whole path must be part of the package declaration.
I would much prefer not to do this this way, but no one else is using eclipse on this project.
Thanks for any help in advance.
In the Package Explorer, right click the src folder and select Build Path > Remove from Build Path
Then find the src/main/java folder, right click java and select Build Path > Use as Source Folder
Basically this tell eclipse that java is the folder which contains the packages and source files.
P.S. This is a very normal project setup for building with Maven. If you download the m2e (Maven to Eclipse) plugins and choose to create a Maven Project (or import from the pom.xml) then Eclipse will automatically know how to correctly locate the source folder.

STS cannot import existing file system into workspace

I followed following steps.
Start STS (Starts with default project named "Servers" already created)
right click package explorer, click on import -> General -> File System
Select directory -> Click Select All
After this step, I should be able to import my directory into "workspace", instead STS "forces" me to import file system to existing project.
Also, if I try to create a folder into top level workspace, STS does not allow me to do that as well.
I need to be able to import the whole directory into the workspace not a project.
You can only import filesystems into existing projects and you can only create folders in existing projects. The top-level is only for projects.
What you need to do first is create a new project with an external location that is rooted at the filesystem you want to import. The project will be created right there and automatically include all sub-folders.
Alternatively, if the root directory is already an eclipse project, do this:
File -> Import -> Existing projects into workspace -> Select root directory
This is a bit confusing that you can't import a bunch of files and folders as a project, but this is how Eclipse has worked since the dawn of time (I think time started in the year 2000).

Why can't Jython find my .jar file?

I have a jar file (not part of the Java standard library) that I want to use.
I've put myJavaPackage.jar into my project directory, and I'm trying to do import myJavaPackage, but I keep getting ImportError: No module named myJavaPackage. What am I doing wrong?
You need to make sure that Jython knows to search your .jar file for modules, which is done using pythonpath. This will differ depending on your setup, but in PyDev:
In the Package Explorer (the tree on the left), right-click on the project and go to Properties.
Select "PyDev - PYTHONPATH" on the left.
Click the "Add zip/jar/egg" button on the right.
Use the directory tree on the left to browse to the folder containing your jar, then click the checkbox next to the .jar file on the right, and click OK, then OK again.
You should also check that the module name you are trying to import matches the package name as specified within the jar file. Note that the jar file might be named differently to the package, especially if there are multiple packages within it.
If you have the source for the .jar, open up the .java file containing the code you wish to utilise, and look for a line near the top that specifies the package. If you find a line that says something like package foo.bar.myJavaPackage;, then you must do one of
import it like import foo.bar.myJavaPackage, and use the contents like obj = foo.bar.myJavaPackage.someClass, or
import it like from foo.bar import myJavaPackage, and use the contents like obj = myJavaPackage.someClass, or
import it like from foo.bar.myJavaPackage import someClass, and use it like obj = myClass, but careful of name collisions using this method.