`ModuleNotFoundError` When Importing Python Package from Git - python

I'm attempting to install a featurestore package from a private GitHub repo via ssh with the following command:
pip3 install -U git+ssh://git#dsghe.<mydomain>/bshelton/package_test.git#master#egg=featurestore
The install is successful, per the image below:
But when trying to run from featurestore import *, I get a ModuleNotFoundError: No module named 'featurestore' error.
Using pip3 freeze, I see that the package is installed, but not with the <package>==<version> syntax I would expect, but it seems to be referencing the git commit instead as its "version":
I believe that the repo's directory set-up is appropriate for a Python package, per the screenshot below.
A noticeable difference between this package's install and the other packages I've installed is that it seems like only the ...dist-info folder is installed for my featurestore package, while every other installed package includes the actual package directory, in addition to the ...dist-info folder. Using ls ~/.local/lib/python3.6/site-packages:
This is my first time, trying to create a package like this, and I've been referencing the several sources below, but would appreciate some insight from the community as to what I'm missing. Thanks.
https://packaging.python.org/tutorials/packaging-projects/
pip install from git repo branch

The cause of my issue turned out to be a syntax error in my setup.cfg above the package_dir and packages lines, which are important if using a package layout with 'src'. Until I fixed the error, my package installed and imported fine in some contexts but not others

I was able to solve for this by moving my featurestore directory up one level, and getting rid of the src directory. Based on the top answer here, I may have been able to also solve for it by simply adding a __init__.py file directly in the src directory. But for my need, src was really an unnecessary level.
New package directory set-up:
Code ran in terminal:
!pip3 install -U git+ssh://git#dsghe.<mydomain>/bshelton/package_test.git#master#egg=featurestore
from featurestore.featurestore import *

Related

Packages installed with Poetry fail to import

Having a simple yet confusing issue: a package I added with poetry fails to import when I try to use it in a module. Steps taken:
poetry add sendgrid
In a module, import sendgrid
Error: Import "sendgrid" could not be resolved PylancereportMissingImports
Troubleshooting I've tried:
I checked my project's poetry venv dir, and sendgrid is there: 'C:\\Users\\xyz123\\AppData\\Local\\pypoetry\\Cache\\virtualenvs\\nameofproject-py3.10\\lib\\site-packages'
Also checked sys.path(); the path to that site-packages dir is listed
Running poetry install gives me the response No dependencies to install or update
both the pyproject.toml and the poetry.lock files list sendgrid
What is going on?
Well, it turns out it's a matter of VSCode not playing nice and failing to recognize Poetry's virtual environment. I had to run the Python: Select Interpreter command and change the venv directory to the one my project is using, then it was able to recognize the installed packages.
See here for more details on how to do that.

How to install Python package from GitHub that doesn't have setup.py in it

I would like to use the following sdk in my python project -> https://github.com/LBank-exchange/lbank-api-sdk-v2. It has sdk's for 3 languages (I just want the python one). I tried to install it using the command:
pip install git+https://github.com/LBank-exchange/lbank-api-sdk-v2.git#egg=lbank
which gave the error
does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.
Looks like the developer didn't bother to package it properly. It it was me using it, I would fork it on GH, add the setup.py and use the fork. Maybe a good exercise for you?
Meanwhile, to just get it to work, in your project "root":
git clone https://github.com/LBank-exchange/lbank-api-sdk-v2.git
ln -s lbank-api-sdk-v2/python-sdk-api/LBank ./LBank
Then in your code just import LBank. This will leave the cloned repo untouched (so you can git pull to update it later) and just link the module directory to the root. Alternatively you can just include the api directory in sys.path for imports to work.
Think there is nothing to install, if you want to be able to "import" and use it like other packages you install through pip install you can just add the folder to your sys-path:
import sys
sys.path.append("path")

Not able to install a python git hub package

For a class, I need to be able to use this github library: https://github.com/matsselen/pyolab. I am struggling to download/install it in a way that actually works. I am using anaconda for this and commands I've tried include:
conda install pyolab
pip install pyolab
conda install source_code_file_path
pip install -e git+https://github.com/matsselen/pyolab#egg=pyolab
I've saved the source code into anaconda's 'pkgs' folder and in my root folder.
I really don't know much about creating packages but in my searching, I found that the issue might be that there is no setup.py file included in the code on github. I tried to build my own but I can't get that to work. Here is the code I have for that:
from setuptools import setup
setup(name='pyolab',
version='master',
description='IOLab code'
author='mats selen'
packages=['pyolab']
)
Also, I am being required to use the python 2.7 version of the package instead of the newer python 3 version.
Can anyone help point me in the right direction to get this working?
No need to pip-install repository, any python scripts can be used directly from any regular files/dirs on file system.
Just clone the repository:
git clone https://github.com/matsselen/pyolab
and then use sys.path to specify location of library's scripts and import them:
import sys
sys.path.append('./pyolab/PyOLabCode/')
# all dirs from sys.path are scanned by Python when you do import
# and the first matched dir where the module is found is used
import commMethods # importing a script ./pyolab/PyOLabCode/commMethods.py

Pip install and run git repo

I'm trying to pip install a separate git repo into my python project. Pip install seems to work when I run pip install git+https://github.com/XxdpavelxX/myapp. However when I then run my code I get the following error.
Here's my app: https://github.com/XxdpavelxX/myapp
ModuleNotFoundError: No module named 'myapp'
ERROR: could not load /Users/myUser/stuff/callerFile.py
Here's the callerFile.py (in a separate git repo):
from myapp import test
print test.random_print()
I suspect that this is pip install related. When I run pip install git+https://github.com/XxdpavelxX/myapp it seems to pass, however inside of my python venv/lib/python3.7/site-packages I only see myapp-1.0py3.7.eggs-info instead of the actual package. Anyone knowing what I'm doing wrong? Do I need to add my library to pypi for this to work?
Edit: Added the actual url to github repo I'm testing.
Create a folder called myapp and move the __init__.py and test.py files to that folder.
Add the following line to your setup.py (I added after url),
packages=['myapp'],
Now installation will be successful and you can import your package.
What is setup.py?
You don't need to post your code to pypi.
I suggest you to use tag #egg to set package name.
So the pip status would be like
pip install git+https://github.com/myGitUser/myLibrary#egg=myLibrary
Your package has neither py_modules nor packages hence it doesn't install anything importable when installed.
My advice is to rename your __init__.py to myapp.py and add this to setup.py:
setup(
…
py_modules=['myapp'],
…
)

YouCompleteMe post install error : cannot import name _compare_digest

I am trying to install YouCompleteMe plugin on a source compiled Vim instance. I have a server without sudo privileges, hence I had to compile new Vim (7.4+) in order to make most plugins work. Also, I have installed miniconda and thus refer to the python in miniconda for all installations.
While following all steps how to install YouCompleteMe plugin (via Vundle or even manually), I faced this issue : "Cannot find module urllib3". So I installed urllib3 via pip, and then the error changed to "cannot import name _compare_digest". Point to note that conda virtualenv (I have just made the miniconda bin to $PATH) cannot start and it still shows "Cannot find module urllib3" even after installing it explicitly.
Is there something wrong with the way I installed vim? I had been extra careful to point to miniconda python wherever it's needed. How do I mitigate this issue and get the plugin running again?
When I had trouble with dependencies I had to run
git submodule update --init --recursive
in the YouCompleteMe directory to get the dependencies installed.
Also make sure you have taken all of the other steps here:
https://valloric.github.io/YouCompleteMe/#full-installation-guide
One of those steps may fix the issue.
In Short
Just go to ycmd submodule inside YouCompleteMe folder, or to be exact in the YouCompleteMe/third_party/ycmd and the run the git submodule command bellow.
git submodule update --init --recursive
Explantion
I've got the same issue like yours,
It was caused by the submodule of YouCompleteMe not being cloned properly.
This command should be able to solve the problem.
git submodule update --init --recursive
But unfortunately the problem still persist, the problem at which urllib3 not found , and instlling the library using pip won't be able to solve this issue.
The problem actually located in ycmd submodule at which needing urllib3 or to be more precise the requests submodule of ycmd needed it.
After some experimenting, the main problem was the git submodule command unable to properly clone the submodule, at which rasing an error about module not found.
Hope, this can be a help for you :)

Categories

Resources