i installed django cms correctly but it says no module named menu_pool
do i have to install other menu plugin?
this path from menus.menu_pool import menu_pool i cannot find, what is the problem? can someone please help me find the clue
i followed the django-cms docs as written here: http://docs.django-cms.org/en/2.3/getting_started/tutorial.html#configuration-and-setup
It looks like Python can do import menus just fine, otherwise the error message would be different. A quick search through the docs for menus reveals that you likely want MenuPool instead of your second menu_pool.
If I'm not mistaken, from menus.menu_pool import MenuPool should give you your expected behavior. Then MenuPool will be in your namespace, so you can do nodes = MenuPool.get_nodes(), and anything else you wish.
Not much experience with django but you should check the module files installed on your system itself to see if there is some mistake or not.
You can get the directory address from sys.path variable in python itself.
Most of the time source is installed with python modules, so you can open up those files and see for yourself if this module is really there or not.
Or you can use the dir(menus) to see what modules are there under menus.
Related
Whenever I try to import the libraries "beautifulsoup" or "requests" I always get the same error. The error I get looks like this... ModuleNotFoundError: No module named 'bs4'. I already have these libraries installed I just can't seem to figure out what's wrong.
If you look at the image below, I noticed when I use the recommended interpreter I get a problem saying "Import "bs4" could not be resolved from source". However, when I select one of the other Python 3.10.7 interpreters the problem goes away(see second picture). Either way I still get the Module not found error. I was thinking this info might help diagnose the problem I'm having.
I think you need to cross check environmental variable path of python and editor interpreter path
so, may be possible you downloaded that library but it available on another path for that he can't reach out and you get error
I have an package thats imported from the parent path everywhere. So i have to set PYTHONPATH enviromentvariable when i want to serve the docs for that package.
Ive searched the Docs,stack overflow, google but couldn't find an solution to configure that in the mkdocs.yml or run an piece of python code to append it to sys.path
Edit:
handlers:
python:
setup_commands:
- import sys;sys.path.append('..');print(sys.path)
could be what i search for, but during mkdocs build (or serve) the print is never called
The solution is really to use the setup_commands. Prints don't seems to be showed there and my problem was that an used package wasn't installed. The error message then is the same as when the import isn't be found.
I have searched through the existing questions on stackoverflow and wasn't able to find what I am looking for. Firstly, I am new to Python, I come from Ruby so some things seem unclear to me in Python. I learn by doing so I am writing my own python REST API client for a payment gateway, which I plan on releasing to PyPi. The problem I have is importing modules from different folders.
Let's say I have the folder structure like this:
my_project/src/lib/directory1/module1.py
my_project/src/lib/directory2/module2.py
In my_project/src/lib/directory1/module1.py I want to import a function defined in my_project/src/lib/directory2/module2.py so
# my_project/src/lib/directory2/module2.py
from lib.directory2 import module1
This doesn't work, it says ImportError: No module named directory2. I read that in Python you need to add the module to the PATH but I have gone to PyPi and took the first library from the top (SeleniumBase) to look at how the code is organised in the GitHub project and I don't see they do any stuff like that. Could you please explain to me how this works and how I can organise my codebase to be able to import modules in one module from different folders to build my own library?
I read this article https://docs.python.org/3/reference/import.html and tried what they say in section 5.7. Package Relative Imports but it doesn't work
In theory this should work
from ..subpackage2.moduleZ import eggs
But it doesn't. I get SystemError: Parent module '' not loaded, cannot perform relative import.
Import will only work if the module you are trying to import is in the same directory as the script that is doing the import.
Otherwise you have to specify the path.
Like this :
import my_project/src/lib/directory1/module1.py
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.
It's weird to me that the import fails even when it's in the sys.path.
today, I set up a google app engine django environment on ubuntu in my lab's pc. And it works fine when I checked out the code and ran it in windows(same pc in the lab).
But when I went to the dorm, and checked out the code and start to run, it failed weirdly.
I print the sys.path, like this:
['/home/tower/googlecode/mygae', '/home/tower/googlecode/mygae/.google_appengine', '/home/tower/googlecode/mygae/.google_appengine/lib/antlr3', ...]
and when I ran python complained
from google.appengine.api import apiproxy_stub_map
ImportError: No module named appengine.api
it's easy to know the google module is in the '/home/tower/googlecode/mygae/.google_appengine'
directory, and the__init__.py for each module is present.
So what can be the reason for this weird thing? Or what I messed up probably?
thanks.
Can you import google and google.appengine?
Are you sure interpreter has read and traverse access rights to the module tree?
I had the same problem on Ubuntu when I wanted to play with google.appengine in console. First I tried to fix it by removing the /usr/lib/python2.7/dist-packages/google package altogether but Ubuntu One complained. Finally I resolved it by merging the GAE SDK google package into the package that caused the collision.
The contents of the /usr/lib/python2.7/dist-packages/google dir now look like this:
/google
/appengine
/net
/protobuf
/pyglib
/storage
/__init__.py
/__init__.pyc
Looks like you're getting a module (or package) called 'google' from elsewhere -- perhaps /home/tower/googlecode/mygae -- and THAT google module has no appengine in it. To check, print google.__file__ and if possible google.__path__; that should be informative.
Sometimes you can get an import error for a module when the error is something different, like a syntax error. Try putting
import pdb;pdb.set_trace()
just before the import and then s(tep) into the import, and n(ext) thruogh the module in question to see of you get an error.