I have created a conda environment and activated it already.
Then inside the use_cases/ directory I execute: pip install -e use_case_b (https://github.com/geoHeil/dagster-demo/tree/master/use_cases):
...
...
Installing collected packages: use-case-b
Attempting uninstall: use-case-b
Found existing installation: use-case-b 0.0.0
Uninstalling use-case-b-0.0.0:
Successfully uninstalled use-case-b-0.0.0
Running setup.py develop for use-case-b
Successfully installed use-case-b
Now when inside the use_cases/ directory:
python
import use_case_b
works fine.
When switching to a different directory like: / (= the root of the repository I get an error message of:
ModuleNotFoundError: No module named 'use_case_b'
Why is it working once and failing in the second place? Could it be that it is not even working in the first place and only importing the sub_directory due to the __init__.py file?
How can I get the python package properly install into the virtual environment?
FYI: here you can find the full project https://github.com/geoHeil/dagster-demo
When using the cookiecutter to set up the package it works just fine.
https://github.com/audreyfeldroy/cookiecutter-pypackage
This is more like a workaround than an solution to the SF question - but works nicely and as an additional benefit has some best practices with regards to documentation and testing already built in.
I normally face that problem when im using pip to install a package. Im not sure if this gonna work for you.
In the file you are importing the package copy the following code and run it.
from pip._internal import main
main(["install", "use_case_b"])
Just ignore the warnings'
Good Luck, Let me know if it works.
Related
I've got a couple of projects here for which I'm preparing documentation at the moment, hosted at readthedocs.org. FYI, all of them use poetry and I use custom .readthedocs.yml files with this entry:
python:
install:
- method: pip
path: .
It works fine for most projects, but it fails for two for different reasons during installation of the project via pip:
The first one uses PyGObject, which failes like this:
Package gobject-introspection-1.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gobject-introspection-1.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gobject-introspection-1.0' found
Command '('pkg-config', '--print-errors', '--exists', 'gobject-introspection-1.0 >= 1.56.0')' returned non-zero exit status 1.
Try installing it with: 'sudo apt install libgirepository1.0-dev'
So it seems that PyGObject cannot be installed without some system packages to be installed. I could rearrange the code so that the import is not top-level. But still I need it in the dependencies. Can I tell pip install to ignore this single package somehow? Any other idea?
The second project compiles some C++ code via Cython and fails, because it's missing a library. I use a custom build script in the pyproject.toml:
[tool.poetry.build]
script = "build.py"
generate-setup-file = false
Is there some flag in pip that I could set and retrieve in build.py to skip the compilation? Or is there a better way?
I am starting a custom package called nate-givens-toolkit.
I want to use a module from that package in a Jupyter notebook in a different folder.
Here is my structure
- nate-givens-toolkit/
- setup.py
- nate_givens_toolkit/
- cloud_io.py
- __init__.py
- project/
- project_nb.ipynb
I am going into nate_givens_toolkit (in the console) and running: pip3 install .
The output I get looks like everything is just fine.
Processing /home/ec2-user/nate-givens-toolkit
Building wheels for collected packages: nate-givens-tooklit
Building wheel for nate-givens-tooklit (setup.py) ... done
Created wheel for nate-givens-tooklit: filename=nate_givens_tooklit-0.1-py3-none-any.whl size=2009 sha256=7de8c9d2930d531603c973c7d8079b66f3d4326fb274e63087128fb7d25d9e1b
Stored in directory: /home/ec2-user/.cache/pip/wheels/17/96/2f/0073c92cfdadbb032d855f24df4725bf190d39cd1c5bb1d233
Successfully built nate-givens-tooklit
Installing collected packages: nate-givens-tooklit
Attempting uninstall: nate-givens-tooklit
Found existing installation: nate-givens-tooklit 0.1
Uninstalling nate-givens-tooklit-0.1:
Successfully uninstalled nate-givens-tooklit-0.1
Successfully installed nate-givens-tooklit-0.1
But if I go into project_nb.ipynb and write:
from nate_givens_toolkit import cloud_io as cloud
I get: ModuleNotFoundError: No module named 'nate_givens_toolkit'
The same thing happens if I run python from the console. As long as I'm in the nate-givens-toolkit directory I can import and run it fine. But if I navigate up a level and try the import I get ModuleNotFoundError.
I don't understand why pip install seems to work, but I still get this ModuleNotFoundError. I thought the whole point of the pip install would be that I could then import from files in other directory without having to worry about relative paths and such. (I've done this exact same thing in a totally different context for work and it was fine.)
I've tried the solutions for similar issues like these:
after pip successful installed: ModuleNotFoundError
ModuleNotFoundError: No module named 'requests' after pip install
So far, haven't found anything that works.
Everything I'm doing is inside the same conda venv.
Help?
I found the answer to my question here: Import py file in another directory in Jupyter notebook. (Note: it wasn't the accepted answer on that post, it was the second answer after the accepted answer.)
The trick is that I needed to do use the -e flag when using pip install.
So instead of
pip install .
I had to run
pip install -e .
Once I ran that, it worked in Python from the console and also in Jupyter.
I'm running python 3.6 via anaconda 3, using Visual Studio Code.
I followed instructions like these (Interactive Brokers API install) and downloaded the package to a local directory of mine say: c:\dev\pyib, so now the code is in c:\dev\pyib\IbPy-master
I open that directory in command line and run
python setup.py install
All runs ok.
But then my program, which is in c:\dev\pyib says Module not found. (In my case ibapi). The linter is also showing red.
There is no other python installed on this pc.
Where did the package install to? and how do I check that? What will I find where the package installed itself to that shows me its there?
Or do I have to use a trial-and-error with the linter and sys.path.append()? (I tried that with the directory where the files are downloaded to - to no avail)
I'm trying to set up the PYTHONPATH using the "env" in launch.json from Visual Studio Code, as shown in this unaccepted answer.
Current sys.path:
'c:\\dev\\pyIb',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\python36.zip',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\DLLs',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-
packages',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\Babel-2.5.0-py3.6.egg',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32\\lib',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\Pythonwin'
I deleted the ib directory and re-ran the install. The last line says: Writing C:\Users\user\AppData\Local\Continuum\anaconda3\Lib\site-packages\IbPy2-0.8.0-py3.6.egg-info So is the location of the egg-info the location of my undetected module? The actual folder in the site-packages is called ib.
Or could my problems be because of a difference in Lib vs. lib with the lowercase in the sys.path and the uppercase in the actual directory?
But the real question here is still: HOW DO I KNOW WHERE the package was installed what should I search for?
This answer is specific for anaconda3 Python and packages installed using python setup.py install (which is actually using distutils)
Take a look at anaconda3\Lib\site-packages you should see a directory for the package you installed.
The way to know for sure where your package is, is by doing a pip list then trying to pip uninstall and re-install again using the python setup.py install: Here are the detailed instructions:
When uninstalling, pip will tell you it cannot because it was done via distutils.
You'll get a message like this:
DEPRECATION: Uninstalling a distutils installed project (ibpy2) has been deprecated and will be removed in a future version.
This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
You'll be prompted to continue anyway. If you choose No, then you can find the directory in
C:\Users\<yourusername>\AppData\Local\Continuum\anaconda3\Lib\site-packages
Thanks to Emanuel Mtali for pointing me in the right direction
Some more information:
The problem I had was due to a stupid mistake of mine. I was running setup of a different (but related) package not used anymore. IbPy2 instead of TwsAPI. I was supposed to run the setup.py of the package installed via the latest version of the MSI from IB, and NOT the IbPy2 package. :-(
I am trying to install the python submodule ANCA in my mac, for which I have run the following:
pip install git+https://github.com/acadev/anca.git
getting the following:
.
.
.
Installing collected packages: anca
Running setup.py install for anca ... done
Successfully installed anca-0.1.5
I have miniconda installed in my computer, and I have checked that the module and its files and dependencies are correctly located in /usr/local/miniconda2/lib/python2.7/site-packages/anca
When I import anca in my notebook it does not give me any error, but if I try to import a submodule it gives me the following error:
from anca import IterativeMeansAlign
ImportError: cannot import name IterativeMeansAlign
It is the same with other submodules, but all of them are apparently well installed with all their files.
I have also tried to install the package using Git:
git clone https://github.com/acadev/anca.git
sudo python setup.py install
with the same result.
Note: 'locate' is not able to locate the module anca unlike the rest of the python modules although I can see all the files in the right location. It is the first time this happens to me.
Thanks a lot for your help,
any suggestion will be very appreciated.
I am trying to export a GeoTiff with Blender using the Blender Python API (based on Python 3), so I've decided to install GDAL on Ubuntu (14.04). What I would like is to get the module as a standalone folder that I could put in the modules directory of Blender (/home/user/.config/blender/2.73/scripts/modules).
The thing is I've run through several different problems trying to install GDAL. I've tried to install from source (for GDAL 2.0.0) here : Official PyPi Gdal
I ran sudo apt-get install libgdal-dev gdal-bin (I list it here because it may be important)
When I am in the extracted GDAL folder, using python setup.py build & python setup.py install, the library installs to /usr/local/lib/python2.7/dist-packages/osgeo. However, when I run python from command line, running from osgeo import osr returns ImportError: No module named _gdal
Following GDAL via pip , I used pip (pip install GDAL) to install the library, and the folder it went to was /usr/lib/python3/dist-packages/osgeo (using pip show ...). Again, running python3 and trying to import results in the same error. Of course, when I copy-paste each folder in the blender module directory, I get the same error in the Blender Python console.
So I decided to compile the sources using ./configure --with-python & make & make install in the source folder. I then copied the folder GDAL-x.x.x/build/lib.linux-x86_64-3.4/osgeo to the blender modules directory and got this time the error when importing : ImportError: /home/yvesu/.config/blender/2.73/scripts/modules/osgeo/_gdal.so: undefined symbol: _Py_ZeroStruct.
Trying to compile with python3 using python3 setup.py build returns the error error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
EDIT 1:
I think I've found the solution : I went to the directory swig/python (not found in a GDAL-1.11.0 folder but gdal-1.11.0 fodler, can't remember where I downloaded it from), ran python3 setup.py build & python3 setup.py install and could finally find the folder in /usr/local/lib/python3.4/dist-packages/GDAL-1.11.0-py3.4-linux-x86_64.egg/osgeo. When I put this osgeo folder oni the Blender modules directory, I was able to import osgeo in Blender. I will report if anything went wrong.
I think I've listed all my attempts at installing GDAL on Ubuntu. Can anyone point me in the right direction? Do you think it is even possible to install it as a standalone module, or do I need linked libraries through LD_LIBRARY_PATH?
Here is the solution I've found :
Download Gdal sources (v2.0.0 is the current stable release) from ftp://ftp.remotesensing.org/gdal/2.0.0/ or http://download.osgeo.org/gdal/2.0.0/ and untar
Go to the directory gdal2.0.0/swig/python
Run python3 setup.py build & python3 setup.py install
Finally find the module folder in, on Ubuntu : /usr/local/lib/python3.4/dist-packages/GDAL-2.0.0-py3.4-linux-x86_64.egg/osgeo
I can now use it in Blender (copying in the modules directory)