Unable to import a package located in the same directory

golang import local package
go modules import local package
python import package
python import module from directory
python no module named same directory
golang import relative path
could not find go mod for project
go import path

I want to import in the current file or package other file located in the same project in a directory. I'm doing this:

import (

// "./dir1"
  "/Users/my_name/my_project/dir1"

)

None of them works

  1) Cloning into '/Users/my_name/go/src/github.com/github_username/github_project'...
  fatal: could not read Username for 'https://github.com': terminal prompts disabled


  2) package /Users/my_name/my_project/dir1: unrecognized import path "/Users/my_name/my_project/dir1" (import path does not begin with hostname)

How to import a directory located in the current project?

Rename dir1 to to the same name as the package inside that directory, then you can import it with:

import "./package1"

However doing this is not recommended, use GOPATH instead. If you really don't want to use GOPATH, you may want to use Modules in Go 1.11 (but it is still experimental).

Unable to import module in the same directory · Issue #6 , The tradeoffs are: with a temp file, lint whenever you want, but you lose the ability to check the dependencies (especially relative imports); without  Import class from another file and directory in Python When creating a file, it a good way to keep them outside our main file. For this reason, we need to create other files inside the same directory or other directories.

Import paths are not directly paths. They are relative to the GOPATH (found by doing echo $GOPATH).

This implies that go is very opinionated about where you store your code as well. So you will have to move your code to $GOPATH/src/my_name/my_project. If you are hosting your code on something like github then move it to $GOPATH/src/github.com/my_github_name/my_project.

Then when you import your sub-packages:

import "github.com/my_github_name/my_project"

Notice that it is not an absolute path.

Traps for the Unwary in Python's Import System, With that layout and the current working directory being project , Python 2.7 gives the While Python 3.3+ is able to import the submodule without any problems: it is one of the key factors leading to the perception that Python packages are  Now the pylint linter will check files on disk instead, so you will have to open files or save them, and import paths will be understood for more projects. The version of pylint from virtualenv directories, as long as they live in some directory above the file you're editing, will be used instead, unless you turn that option off with g:ale_python_pylint_use_global.

Make sure your project is in GOPATH's go/src folder(Recommended way). Then import like this

package logic

import (
    "project_name/folder_name"
)

Python for the Lab Complete Guide to Imports in Python: Absolute , How to plan your code so imports are clear and clean. The example above is only one case in which the import as is handy. and then it will move to the directories where packages are installed Note that you need to append to the sys.path before you try to import mod_a , or it will fail such as before. In order to import a module or package from a directory that is not in the same directory as the script we are writing (or the directory from which we run the Python interactive interpreter), that module needs to be in a package. As defined above, any directory with a file named __init__.py is a Python package. This file can be empty.

5. The import system, Python has only one type of module object, and all modules are of this type, regardless of Like file system directories, packages are organized hierarchically, and If any of the intermediate imports fail, a ModuleNotFoundError is raised. We need to use the -cp (or -classpath) option to specify the base directory of the package com.yyy, in order to locate com.yyy.Circle.class. d:\myTest> javac -cp d:\myProject\classes TestCircle.java To run the TestCircle , we again get a error, as JRE cannot find the com.yyy.Circle .

pytest import mechanisms and sys.path/PYTHONPATH, pytest will find foo/bar/tests/test_foo.py and realize it is part of a package given that there's an __init__.py file in the same folder. It will then search upwards until it  >>> import sys >>> print sys.path [' /opt/django/myproject ', .. (remaining output omitted) Add __init__. Ensure that a file called __init__ is added to the folder that contains the module you want to import. This file is typically empty. Import Module. Finally import the module using the following syntax 'from <folder>.<filename> import

Good Integration Practices, This ensures your code and dependencies are isolated from your system Python In those directories, search for test_*.py or *_test.py files, imported by their test Python by default puts the current directory in sys.path to import your package,​  Certain packages installed in the site-packages directory on Win10 would not be included in the External Libraries within the project. Tried running as administrator and no different. Same app imported into a PyCharm project worked on Win7. The missing packages were mx.DateTime, xlrd, and xlwt. Python command line worked fine.

Comments
  • did you try adding a period in front of /Users/ to indicate that you're looking under the current directory?
  • Import is by package name, not by path on disk.
  • I don't want to move it anywhere. Other options?
  • You could make s symlink, but be aware you are swimming upstream a little. Its fairly common for a language to have an opinion on where you place your code.