I want to work with Python v3.5.2, but my laptop also has Python 2.7.10 installed (it's a MacBook). I have a simple Python project structure like the following. Note, there might be artifacts that are showing because I am using IntelliJ as the IDE (e.g. *.pyc files and *.iml file).
. ├── io │ ├── __init__.py │ ├── __init__.pyc │ ├── __pycache__ │ │ └── __init__.cpython-35.pyc │ └── me │ ├── __init__.py │ ├── __init__.pyc │ └── model │ ├── __init__.py │ ├── __init__.pyc │ ├── car.py │ └── car.pyc ├── start.py └── test-python.iml
My start.py script looks like the following.
from io.me.model.car import Car
car = Car("honda", "civic", 2005)
print(car.model)
In a terminal, if I type in python3 start.py then I get the following error.
Traceback (most recent call last):
File "start.py", line 1, in
from io.me.model.car import Car
ImportError: No module named 'io.me'; 'io' is not a package
However, I decided to type in python start.py and I actually do get an output: civic.
Any ideas on what I'm doing wrong here?
Also, is there a guideline on a project structure for Python? Coming from a Java world, I'd like to know if there is a recommended best-practice or a highly-opinionated approach to a Python project's structure (e.g. like a typical Java Maven project).
- Where do I put my sources?
- Where do I put in my tests?
- Is there a build tool (like Maven for Java) for Python that would facilitate and guide the directory structure?
ioto something else. May be it's clashing with the inbuiltiopackage. - Mohammad Yusufio, no one else can create a package starting with that namespace? e.g.io.mydomain.project? In Java, you can share anionamespace, though you'd want to get more specific than that, but it's ok to useio. - Jane Waynefrom .io.me.model.car import Car. See if that works. It will import theiopackage from the current directory. - Mohammad Yusuf