No module named x.urls - python

Seem to be having a problem here. Been working off my netbook for a while and brought all my code across to my desktop. Now, I'm getting 'No module named x.urls' on every single page. I don't know why. Works fine on the netbook. All I did was copy and paste all the code across. Also, I'm running 1.2.1 on the netbook and moved across to 1.3 on the desktop. Using DevServer on Debian Testing. Anything I'm missing here?
Everything is in the one urls.py file at the project root. Pastebin: http://paste2.org/p/1419080
My Settings.py (obviously in project root): http://paste2.org/p/1419084
Anything else I should post?
Thanks for all the help!

Name the directory where you put you project 'x' and it will work.

Related

ModuleNotFoundError - Python3

New to Python and getting errors when importing modules. I have the following structure (not sure if this is a good way to show folder structure):
ecommerce
customer
__init__.py
contact.py
shopping
__init__.py
sales.py
__init__.py
I want to import contact.py from customer into sales.py in shopping but get presented with: ModuleNotFoundError: No module named 'eccommerce'.
I'm using this:
from ecommerce.customer import contact at start of the sales.py file.
Any ideas?
VSCode, MacOS 10.14.6
One thing to pay attention to is where is your current working directory located. If you have the cwd set to be in ecommerce than you should be able to access the contact with the syntax you inputted.
I ran into this issue several times and in the python documentation this setup should technically work, init files being parsed by the python parser as individual packages which you can then access. It seems though that it won't work with the standard python interpreter and I haven't found the answer why. One way to get around this is to do as #Sory suggests, at the beginning of your package entry, add the path to the environment variable. This is a work around though and can lead to problems later on.
Another option is to use a separate python interpreter, i use for example the IPython interpreter from Jupyter which runs with this setup perfectly fine. This will give you another external dependency though.
Be sure though that the current working directory is set to be the root folder though as that is usually the first problem.
from ecommerce.customer import contact would work if 'customer' was a class in the ecommerce.py file, but in your case, those are different files so it doesn't work...
The correct syntax would be:
from customer import contact
but you need to adjust those files.
Another way around would be to import os, navigate to that ecommerce folder like so: os.getcwd('insert dir path here'), and then import customer.

PyCharm tells me it cannot find modules although they are there

I started a django project, it's still very basic. There are three apps in it. The app "eventmanager" builds on the app "locationmanager". So I try to import like this:
from locationmanager.models import Location
PyCharm claims that the reference "locationmanager" cannot be resolved. However, when I run my code with the django testserver, it runs just fine. Did I do something wrong while setting up PyCharm?
EDIT: Screenshot of my project structure in PyCharm
When you import a django project into pycharm, you have to set the django project folder in pycharm as the Sources Root for the reference resolving to work properly.

Do I always need to set PYTHONPATH to my project?

I was having trouble to import modules of own project to other files of the project. I have a directory structure that looks like this:
my-project/
|-main.py
|-test/
|__init__.py
|-test_service_class.py
|-services/
|__init__.py
|-service_class.py
I wanted to import service_class.py to test_service_class.py, so I coded:
from services import service_class
Then I got an error saying that services is not a module... I searched a lot about it and got two ways to fix this error.
The first was adding the following weird code on the top of the files, witch looks really wrong, but works:
import sys
sys.path.append('<path_to_module>')
And the other was adding my Project's path to my PYTHONPATH...
I'm actually using the PYTHONPATH option, that looks more "correct", still I think it's weird because for each Project I start, I'll have to include the path to PYTHONPATH...
So I wanted to know if is it the best way to fix this problem, if aren't there better options, because I never had to set my Project's directory on PYTHONPATH before.
Thank you, I'm looking forward for answers!

Python 2.7.9 troubles importing pysftp

I've been having troubles import pysftp. I currently have a server running some python scripts on a database, and decided to try and update this module which some of the scripts use. It broke a bunch of the scripts and then I had to go back and fix the versioning and to allow everything to function.
So far the only module I'm not able to import or use is pysftp. It throws the attached error. I've tried going into sites-manager and removing the files from there, however it has yet to help. Everything else has been working. Updating doesn't work either.
Any indication on how to resolve this error is greatly appreciated.
Error is:
ImportError: cannot import name util
I haven't been able to find a package called util to install. Please help! Attached link is of the trace.
http://imgur.com/a/9lQUj

Python Throws ImportError: No module named..." Error

I'm trying to install the Chilkat library for Python in order to use its encryption functionality, but being new to Python in every possible way, I'm getting stuck entirely too early. I've installed the library as instructed by the docs and verified that the files are in the "right place" (/usr/local/lib/python2.7/site-packages/) on my Ubuntu 12.04 server.
I've also downloaded the test script. When I try to run it, however:
ImportError: No module named chilkat
I know this is stupid basic, but here I am. In the docs they do mention a possible issue with sys.prefix. That (presumably default, since I've never touched it) value on my machine is /usr. I moved everything there, but still get the same error.
Help? Where is the most "pythonic" place to put these files and how can I get Python to recognize them universally?
Thanks.
For anyone searching, I just ended up adding site-packages to my sys.path by adding a .pth file to dist-packages which was already in my path.
echo "/usr/local/lib/python2.7/site-packages" > /usr/local/lib/python2.7/dist-packages/site-packages.pth

Categories