I am trying to use fbconsole.
The website say
pip install fbconsole
But I dont have pip, so I use easy_install fbconsole and fbconsole is installed.
I check Python directory and there is fbconsole-0.3-py2.7.egg file.
I try to import fbconsole, but the error is
Internal Server Error
import_string() failed for 'myapp.views.index'. Possible reasons are: - missing __init__.py in a package; - package or module path not included in sys.path; - duplicated package or module name taking precedence in sys.path; - missing module, class, function or variable; Debugged import: - 'myapp' found in 'D:\\PythonProj\\LLL\\myapp\\__init__.pyc'. - 'myapp.views' not found. Original exception: ImportError: No module named fbconsole
UPDATE 1: My Project structure is
which is quite different with your explanation because I am using KAY framework.
I follow your explanation but still fail to import the package.
you need to put the fbconsole module into your GAE project to make it work.
installing it via pip or easy install does make it available for your local python but not for the GAE project.
When I pip install fbconsole I don't get an .egg file, but an .egg-info file, which is only metadata, along with the project files fbconsole.py and fbconsole.pyc. It appears a source package is the only uploaded format on PyPI, so it appears your issue is you need to copy the fbconsole.py file (and optoinally fbconsole.pyc, although it will rebuild this file on first access) to your packages directory if you're using my path_fixer.py script, or to the root of your project if not.
Here's more info about the differences between .egg and .egg-info files.
There are two basic formats currently implemented for Python eggs:
.egg format: a directory or zipfile containing the project's code and resources, along with an EGG-INFO subdirectory that
contains the project's metadata
.egg-info format: a file or directory placed adjacent to the project's code and resources, that directly contains the project's
metadata.
http://svn.python.org/projects/sandbox/trunk/setuptools/doc/formats.txt
Related
I have the current 'noise' package 2.2 in python3.8
It appears to have a circular import problem;
I do not believe I have any similarly named files in my own folders.
My code:
import noise
Result>
import noise
File "C:\Python\Python38\lib\site-packages\noise\__init__.py", line 12, in
from . import _perlin, _simplex
ImportError: cannot import name '_perlin' from partially initialized module 'noise' (most likely due to a circular import) (C:\Python\Python38\lib\site-packages\noise\__init__.py)
From a Github issue regarding this problem:
What's happening is that Python prefers to look for modules in relative paths before absolute paths. Since you can import noise from the repo directory, that means it's probably already in your python path(an absolute path).
Say this repository lives in foo/noise/ and now you are in foo/ if you go up a directory and try to run import noise. Python will see that the local directory noise/ as a module because it has an init.py file and try to import the directory instead of the module installed in your python path. Since this module requires the _noise and _simplex C extensions to be compiled, this wont work.
I'd recommend removing or renaming this repo directory from your project and use pip to install noise if you haven't already. (pip install noise)
If you really want to install from source and not install into your system, then, in the noise/ repository, run python setup.py build to build locally and grab dist/lib*/noise/ and put that directory into your project directory.
Alternatively use python setup.py install in the noise/ repository to install from source into your Python path.
This is the error I am facing right, I google it a lot but solutions did not work, I am using python 3.7 in my django application.
Code:
from libs.strings import *
Error:
ModuleNotFoundError: No module named 'libs.strings'
As I have checked the libs module from pypi. The libs module doesn't seem to have strings. So doing pip install libs wont solve your problem.
Maybe libs could be a directory in your project you are trying to access. If so, then:
Check Proper path for libs folder.
In order to define libs as a single package, add empty __init__.py file in each folder; so the whole directory system act as a python module.
I am using Python 3.6.5, installed via miniconda. My issue is arising from the fact that I'm pip installing a package that has the same namespace as a local package. After pip installing this package, I can no longer import from the local package. I receive a ModuleNotFoundError error. The namespaces need to stay this way, if possible.
Here is my directory structure:
/root
stuff
- __init__.py
- my_stuff.py
app.py
init.py
__import__('pkg_resources').declare_namespace(__name__)
app.py
from stuff.my_stuff import my_fun
This works fine until I pip install the package with the same namespace, "stuff". After pip installing the package, the import statement, from stuff.my_stuff import my_fun throws the following error: ModuleNotFoundError: No module named 'stuff.my_stuff'. I kind of understand why. When importing modules in Python, it will look for built-in modules first, then sys.path, PYTHONPATH etc...
Here's the part thats really confusing me. If I create another arbitrary local module, like some_stuff, as shown below:
/root
stuff
- __init__.py
- my_stuff.py
some_stuff
- __init__.py
- more_stuff.py
app.py
and if I then run:
app.py
from some_stuff.more_stuff import more_fun
from stuff.my_stuff import my_fun
Everything works as expected. i.e. if I import some_stuff.more_stuff before stuff.my_stuff, everything works. But not vice versa. Solely importing stuff.my_stuff causes the ModuleNotFoundError.
app.py
# The code above works, but this causes the error
from stuff.my_stuff import my_fun
What is causing this behaviour? How can I solve this issue of locally referencing a package with the same namespace as one that was pip installed?
Edit:
I continued experimenting and noticed that when I remove all __init__.py files, everything works as expected. I came across this post: Since Python 3.3, a folder without an __init__.py can be considered part of an implicit namespace package. I'm still confused about the behaviour mentioned above though.
This SO question should answer your question
I am still putting the original answer here for convenience.
It's not possible to change "import path" (installed name) by specifying arguments to pip. You can, however, make some changes to the package after installing:
use pip install -e git+http://some_url#egg=some-name that way even if both packages have the same import path, they will be saved under different directories (using some-name provided after #egg=). After this you can go to the source directories of packages (usually venv/src/some-name) and rename some folders to change import paths
fork the repository, make changes, then install the package from that repository. Or you can publish your package on PyPI using different name and install it by that name
use pip download to put one of the packages in your project, then rename folders as you like
My project isn't building with autodoc. I'm running into this frequently asked question about my project not building in autodoc. But, some of dependencies include c code which won't execute on Build the Docs servers. So I read the approach in this blog explaining that I should use mock. This relates to the stackoverflow question 'how-to-mock-so-that-from-x-import-works'.
In the advanced settings section of the admin page on Read the Docs, there's an option to use virtualenv, which I checked, and then the path to the root of my project to requirements.txt is requested.
The project directory is structured as:
GatherNews/
requirements.txt
When I use GatherNews/requirements.txt as the path. I get the error:
/var/build/user_builds/gathernews/checkouts/latest/docs/api/grss.rst:10: WARNING: autodoc: failed to import class u'CaptureFeeds' from module u'gathernews.gRSS'; the following exception was raised:
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/gathernews/envs/latest/local/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 335, in import_object import(self.modname)
File "/home/docs/checkouts/readthedocs.org/user_builds/gathernews/envs/latest/local/lib/python2.7/site-packages/gathernews/init.py", line 1, in import gRSS
File "/home/docs/checkouts/readthedocs.org/user_builds/gathernews/envs/latest/local/lib/python2.7/site-packages/gathernews/gRSS.py", line 38, in import feedparser
ImportError: No module named feedparser /var/build/user_builds/gathernews/checkouts/latest/docs/_themes/README.rst:: WARNING: document isn't included in any toctree
My question is how do I tie this all together? Specifically, am I using the correct path to my requirements.txt for Read the Docs to build successfully? If my path to my requirements.txt is correct, then how can I include the mock package to successfully generate autodocs?
I created a fork of https://github.com/Bonza-Times/GatherNews and set of a ReadTheDocs build for it. The only issue seems to be that you used the wrong path to requirements.txt. It says
Path from the root of your project.
so that does not include GatherNews. Just use requirements.txt as the path, since that file is in the top level of your git repository.
Since you've got Use virtualenv checked, ReadTheDocs should automatically take care of making sure the virtualenv's site-packages are available in sys.path to the sphinx-build script.
I don't see any need for mocking modules, since feedparser doesn't have any hard dependencies on C libraries. It can be built against libxml2, but it doesn't have to.
With the path to requirements.txt fixed I was able to do a successful build.
These are the "Advanced Settings" I used, the remaining settings are at default values:
I am using setup.py to create a python package, which I want to install via pip. To correctly install the files under
lib/python2.7/site-packages/<package-name>
I used the following option in setup.py:
'package_dir': {'':'lib'}
as described here but get an error
error: package directory 'lib' does not exist
Well, there is no such directory as I want the current directory to be installed as package lib or whatever. I also tried to use
'package_dir': {'mycode':''}
which installes the code directly in
lib/python2.7/site-packages/
and not under
lib/python2.7/site-packages/<package-name>
What am I doing wrong, and where is this documented? I might overlooked the documentation of this basic feature as the documentation for setup.py is 'suboptimal'.
The description to how to do this an be found in the distribute documentation... Within a directory containing all of the project (TowelStuff/ in the given example) you specify the name of the actual module (towelstuff/). To include this as your module you need to add the following line in setup.py:
'packages': ['towelstuff']
After having created the sdist (from within TowelStuff/), the installation of this package will install it under site-packages/towelstuff, which can be imported as usual (from towelstuff import ...).