Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
595 votes
15 answers
708k views

beyond top level package error in relative import [duplicate]

It seems there are already quite some questions here about relative import in python 3, but after going through many of them I still didn't find the answer for my issue. so here is the question. I ...
shelper's user avatar
  • 10.4k
208 votes
9 answers
206k views

How to use custom packages

I'm trying to create and use a custom package in Go. It's probably something very obvious but I cannot find much information about this. Basically, I have these two files in the same folder: mylib.go ...
laurent's user avatar
  • 89.9k
207 votes
15 answers
537k views

Can't import my own modules in Python

I'm having a hard time understanding how module importing works in Python (I've never done it in any other language before either). Let's say I have: myapp/__init__.py myapp/myapp/myapp.py myapp/...
user avatar
137 votes
9 answers
50k views

#import using angle brackets < > and quote marks " "

I'm wondering what decides whether you're allowed to use <Header.h> or "Header.h" when you're importing files in Objective-C. So far my observation has been that you use the quote marks "" for ...
quano's user avatar
  • 19k
129 votes
3 answers
210k views

Python: importing a sub‑package or sub‑module

Having already use flat packages, I was not expecting the issue I encountered with nested packages. Here is… Directory layout dir | +-- test.py | +-- package | +-- __init__.py |...
Hibou57's user avatar
  • 7,030
93 votes
6 answers
32k views

Do unused import and objects have a performance impact?

Do the unused imports and unused objects in Java code create any performance impact? Suppose an object is initialized and never used, what happens? And what is the cost of unused imports?
Dheeraj Joshi's user avatar
91 votes
3 answers
38k views

How python deals with module and package having the same name?

Suppose I have a module foo.py and a package foo/. If I call import foo which one will be loaded? How can I specify I want to load the module, or the package?
Charles Brunet's user avatar
62 votes
2 answers
36k views

Access main package from other package

I want to access the main package from another package, but this is impossible because the main file isn't in a directory. I already tried putting the main file in a directory, but when I try to ...
Jan Wytze's user avatar
  • 3,457
56 votes
7 answers
38k views

How to reference python package when filename contains a period

I am using django and I have a file named models.admin.py and I want to do the following idea in models.py: from "models.admin" import * however, I get a syntax error for having double quotes. But ...
Alexander Bird's user avatar
55 votes
14 answers
423k views

Java Package Does Not Exist Error

So there's a folder /usr/share/stuff in the root directory in stuff there are a bunch of java files with package org.name definitions at the top I am running javac test.java where test.java is in a ...
algorithmicCoder's user avatar
54 votes
3 answers
30k views

How do you organise a python project that contains multiple packages so that each file in a package can still be run individually?

TL;DR Here's an example repository that is set up as described in the first diagram (below): https://github.com/Poddster/package_problems If you could please make it look like the second diagram in ...
Pod's user avatar
  • 4,125
49 votes
3 answers
64k views

importing a module in nested packages

This is a python newbie question: I have the following directory structure: test -- test_file.py a -- b -- module.py where test, a and b are folders. Both test and a are on the same level....
khelll's user avatar
  • 23.9k
49 votes
2 answers
136k views

How to use org.apache.commons package?

On various web examples I see imports such as: import org.apache.commons.net.ftp.FTPClient; I don't understand how to use these, and the apache website is fairly unclear. How to I use these classes? ...
Connor's user avatar
  • 1,973
46 votes
4 answers
19k views

Relationship between a package statement and the directory of a .go file

See this experiment. ~/go/src$ tree -F . ├── 1-foodir/ │   └── 2-foofile.go └── demo.go 1 directory, 2 files ~/go/src$ cat demo.go package main import ( "fmt" "1-foodir" ) func main() { ...
Lone Learner's user avatar
  • 19.8k
44 votes
1 answer
88k views

Import and usage of different package files in protobuf?

I have imported an other proto which having different package name than mine. For usage of messages from other package, have accessed that message with package name. For Example : other.proto ...
Muthurathinam's user avatar
42 votes
5 answers
102k views

Python package import from parent directory

I've the following source code structure testapp/ ├─ __init__.py ├─ testmsg.py ├─ sub/ │ ├─ __init__.py │ ├─ testprinter.py where testmsg defines the following constant: MSG = "Test message&...
user avatar
39 votes
1 answer
28k views

Flask('application') versus Flask(__name__)

In the official Quickstart, it's recommended to use __name__ when using a single module: ... If you are using a single module (as in this example), you should use __name__ because depending on ...
nalzok's user avatar
  • 15.8k
39 votes
1 answer
16k views

When or why to use relative imports in Python [duplicate]

Are there any rules or guidelines concerning when to use relative imports in Python? I see them in use all the time, such as in the Flask web framework. When searching for this topic, I only see ...
trinth's user avatar
  • 6,019
37 votes
6 answers
210k views

Help with packages in java - import does not work

I'm a C++ developer - not a java developer, but have to get this code working... I have 2 public classes that will be used by another product. I used the package directive in each of the java files. ...
Tim's user avatar
  • 20.3k
34 votes
8 answers
6k views

Too many imports are spamming my Java code

In my project I have a shapes package which has shapes I designed for my graphics program, e.g., Rectangle and Circle. I also have one or two more packages that have the same names as java.awt classes....
ApprenticeHacker's user avatar
33 votes
1 answer
37k views

"ValueError: unknown locale: UTF-8" when importing pandas in python 2.7 [duplicate]

I'm very new in python and would like to learn using pandas, but I can't even use the package properly in my python. In the terminal I tried $ conda install pandas The result is: Fetching package ...
Hernando Andrianto Willy Ren's user avatar
26 votes
7 answers
152k views

Importing packages in Java

How to import a method from a package into another program? I don't know how to import... I write a lil' code: package Dan; public class Vik { public void disp() { System.out.println(...
Daniel Victor's user avatar
25 votes
4 answers
10k views

How to only import sub module without exec __init__.py in the package

When import sub module from a package, the __init__.py file in the package folder will be exec first, how can I disable this. Sometimes I only need one function in a package, import the whole package ...
HYRY's user avatar
  • 96.5k
25 votes
2 answers
12k views

Import a module from both within same package and from outside the package in Python 3

Okay, the scenario is very simple. I have this file structure: . ├── interface.py ├── pkg │   ├── __init__.py │   ├── mod1.py │   ├── mod2.py Now, these are my conditions: mod2 needs to import mod1....
Akronix's user avatar
  • 2,078
24 votes
2 answers
50k views

Java Package Import Alias [duplicate]

Is it possible in Java to import packages and give this package import a specific name? I currently have a class, which uses some DTO's from a backend and a service package. In both packages the DTO'...
Dirk Rother's user avatar
24 votes
6 answers
54k views

relative path not working even with __init__.py

I know that there are plenty of similar questions on stack overflow. But the common answer doesn't seem to be working for me. I have a file structure like this proj/ lib/ __init__....
samirahmed's user avatar
  • 1,259
23 votes
5 answers
7k views

Python import precedence: packages or modules?

I wasn't clear how to correctly name this question. Case 1 Assume that I have the following directory structure. foo | +- bar/__init__.py | +- bar.py If I have from foo import bar How do I know ...
Jeeyoung Kim's user avatar
  • 5,987
22 votes
2 answers
9k views

import fails when running python as script, but not in iPython?

I have a project structured as such: folder1 | folder2 | tests I have __init__.py in each folder. When I am in the parent directory of folder1, I run iPython ...
Andrew's user avatar
  • 6,811
21 votes
4 answers
75k views

Java referencing a class in the same directory

I created a Pair class in Java (similar to the c++ pair) and am having trouble referencing it from a different java file. I am working inside a Java file, let's call it fileA in the same directory as ...
CodeKingPlusPlus's user avatar
21 votes
5 answers
21k views

Is it possible to use two Python packages with the same name?

I have a question about imports. The question might seem a bit contrived, but its purpose is to explore the limitations of using absolute imports for all imports in a package. PEP8 highly ...
cjerdonek's user avatar
  • 6,079
21 votes
1 answer
26k views

You can mark the path "..." as external to exclude it from the bundle - how?

I have a repository that I published to a package. I installed this package in another repository and want to use it but I get an error: (where the ... are the name of any package that trying to ...
ESI's user avatar
  • 1,987
20 votes
1 answer
13k views

Python files - import from each other

I would like for two of my python files to import some methods from each other. This seems to be giving me import errors. Example: file_A.py: from file_B import do_B_stuff file_B.py: from ...
Chris Dutrow's user avatar
  • 49.9k
20 votes
2 answers
43k views

python import module from parent package

I have the following directory structure foo/ __init__.py settings.py bar/ __init__.py myfile.py In myfile.py I have: import settings I get the following error: ...
danielrvt's user avatar
  • 10.7k
20 votes
1 answer
14k views

Difference in package importing between Python 2.7 and 3.4

For this directory hierarchy: . ├── hello │   ├── __init__.py │   └── world │   └── __init__.py └── test.py And the Python source files: test.py: if __name__ == '__main__': import hello ...
pjhades's user avatar
  • 1,988
20 votes
5 answers
29k views

VSCode 1.39.x & Python 3.7.x: "ImportError: attempted relative import with no known parent package" - when started without debugging (CTRL+F5))

when running Python test from withing VS Code using CTRL+F5 I'm getting error message ImportError: attempted relative import with no known parent package when running Python test from VS Code ...
ShamilS's user avatar
  • 1,532
19 votes
4 answers
28k views

From request import PandaRequest ImportError: No module named 'request'

I am trying to use panda. When I import it as import panda as pd I get this error File "/usr/local/lib/python3.5/dist-packages/panda/__init__.py", line 1, in <module> from request import ...
Bruno's user avatar
  • 641
19 votes
8 answers
6k views

Automatically remove explicit package declarations with import statements in Java

I have a project created by others that includes thousands of class files and has the package names explicitly typed out for every reference to any of their classes. It looks like the code was reverse ...
AlbertoPL's user avatar
  • 11.5k
19 votes
1 answer
2k views

Imports and Depends

I have read two recent posts that discuss Depends and Imports Upcoming NAMESPACE, Depends, Imports changes for 2.14.0 (some definitions/use please) Better explanation of when to use Imports/Depends ...
David Diez's user avatar
17 votes
1 answer
3k views

How to group imports in Rust with conditional compilation?

I am looking to group all my imports with conditional compilation. I know that the #[cfg(target_os = "windows")] attribute organises the import, but it only works for one import. How can I import ...
Akiner Alkan's user avatar
  • 6,722
17 votes
8 answers
93k views

Java error - bad source file: file does not contain class x . Please remove or make sure it appears

Recently started studying Java for an exam. While learning packages, tried this and got an error message. What I did was //Creating class A (Within package the package: com.test.helpers) package ...
user3210872's user avatar
16 votes
3 answers
35k views

python import module from a package

folder structure: <current dir> main.py packages <dir> __init__.py mod.py main py: import packages print packages.mod.hello() mod.py: def hello(): return 'hello'...
andio's user avatar
  • 1,714
16 votes
3 answers
16k views

How does javac automatically compile dependencies of a class

Given the following directory structure: /top |--- wrk |--- pkg |--- A.java |--- B.java Assume that the two files A.java and B.java contain the ...
paidedly's user avatar
  • 1,413
15 votes
6 answers
29k views

Eclipse cant recognize com.sun.net.httpserver.HttpServer package

I have a home-work to create a http server with java , a simple one and from scratch . After searching google and here ...i found this link "see the best response" with a very nice response ,so i copy/...
Andi Domi's user avatar
  • 741
15 votes
3 answers
28k views

R, Python: install packages on rpy2

I'm using R in my Python script through the rpy2 library and I need a package that is not in the default installation of R. How can I install it? install.packages("DirichletReg", repos="http://r-...
Ricky Robinson's user avatar
15 votes
1 answer
7k views

How to solve AttributeError when importing igraph?

When I import the igraph package in my project, I get an AttributeError. This only happens in the project directory: [12:34][~]$ python2 Python 2.7.1 (r271:86832, Apr 15 2011, 12:09:10) [GCC 4.5.2 ...
any1's user avatar
  • 302
15 votes
1 answer
9k views

Running python scripts within a subpackage of my package

Having some trouble figuring out the correct, python 2.x preferred way to do relative imports so that I can keep test scripts together in one subpackage, and have those test scripts be able to test my ...
mcorley's user avatar
  • 767
15 votes
8 answers
16k views

Actionscript 3 import package.* vs import package.Class

In Actionscript 3, is there any reel overhead between importing a full package versus importing independant classes? E.g.: import flash.display.* vs. import flash.display.Sprite I know it's a good ...
user105813's user avatar
  • 17.3k
15 votes
1 answer
20k views

Yet another ImportError: attempted relative import with no known parent package [duplicate]

I have the following directory structure: py_test ├── __init__.py ├── dir1 │ ├── __init__.py │ └── script1.py └── dir2 ├── __init__.py └── script2.py In script2 I want to "import ..\...
sancho.s ReinstateMonicaCellio's user avatar
13 votes
5 answers
219k views

Java : Accessing a class within a package, which is the better way?

If I access a class within a package using fully qualified name, without importing it, whether it saves any memory? Using fully qualified class name : java.lang.Math.sqrt(x); Import package : ...
Jomia's user avatar
  • 3,404
13 votes
6 answers
9k views

Matlab cannot see some of my java classes (not all) in jar package

I have a problem that is driving me nuts. Matlab sees only some of my classes embeded in a JAR file If I compile the classes outside of a package and add the path to the class in Matlab using ...
user1097111's user avatar

1
2 3 4 5
19