AttributeError: module 'syft' has no attribute 'TorchHook' - python

Please seeking help from expert: When I am using pysyft library in python I am getting this error (
AttributeError: module 'syft' has no attribute 'TorchHook')
Here is my code screenshot
[1]: https://i.stack.imgur.com/rPxWw.png
my environment :
Spyder (Python IDE)
Ubuntu 20.04
python3

The version of syft you are using is v0.3.0+. It does not contain syft.TorchHook as I believe I read that it is not needed there.
Use pip install syft==0.2.9 to use syft.TorchHook(). Especially if you are following that Secure and Private Course from Andrew Trask, Openmined.
Note that if you are indeed following that course, a new updated course has been introduced by the Openmined team. See https://courses.openmined.org/courses/foundations-of-private-computation for more details. It is based on an updated version of syft.

I would like to add one additional issue: if you found the following problem when using PIP install syft==0.2.9
Could not find a version that satisfies the requirement torch~=1.4.0 (from syft) (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2)
You can refer to the following methods to solve:
pip install syft -f https://download.pytorch.org/whl/torch_stable.html
Reason:
Not all PyTorch versions are available on Python's package registry PyPI.
-f : adding the custom registry
-f, --find-links <url>
If a URL or path to an html file, then parse for links to archives such as sdist (.tar.gz) or wheel (.whl) files. If a local path or file:// URL that’s a directory, then look for archives in the directory listing. Links to VCS project URLs are not supported.
refer to this link

Related

can I create python package with no publishing to pypi?

following this guide: https://realpython.com/pypi-publish-python-package/
can I just create my Python package but not publish it to pypi.
just install it with pip install and then import my_packeg.
when trying this get No module named my_packeg error
the goal is to using this package code inside x micro service for prevent duplicate code...
From pip's user guide:
pip supports installing from PyPI, version control, local projects, and directly from distribution files.
The command-line to use is different:
There is a suitable command-line use for each of them and pip looks for, in the following order:
When looking at the items to be installed, pip checks what type of item each is, in the following order:
Project or archive URL.
Local directory (which must contain a setup.py, or pip will report an error).
Local file (a sdist or wheel format archive, following the naming conventions for those formats).
A requirement, as specified in PEP 440.
For your specific problem, you don't need to upload to PyPI. Solutions:
Build a "wheel" https://pip.pypa.io/en/stable/reference/pip_wheel/ and distribute that file, pip can install it.
Place a zip archive of the source somewhere on your intranet (or shared file system) and call pip install http://intranet.url/mypackage-1.0.4.zip
source: Can I make pip installable package without registering package in pypi?

pip install from Azure DevOps Python Artifacts feed not working

When I attempt to install a package from our Azure DevOps Artifacts feed, I get the error:
Looking in indexes: https://pypi.org/simple, https://pkgs.dev.azure.com/company/company_Software/_packaging/PyPI/pypi/simple/
ERROR: Could not find a version that satisfies the requirement as-api (from versions: none)
ERROR: No matching distribution found for as-api
As using pip install -vvv potentially produces confidential information, I cannot provide the full log here. Please feel free to ask any specific questions about the log. In the meantime, I can see promising messages like:
Found index url https://pkgs.dev.azure.com/company/company_Software/_packaging/PyPI/pypi/simple/
Getting credentials from keyring for https://pkgs.dev.azure.com/company/company_Software/_packaging/PyPI/pypi/simple/
And some problematic messages?:
Status code 302 not in (200, 203, 300, 301)
Skipping link: not a file: ...
Given no hashes to check 0 links for project 'as-api': discarding no candidates
Reproduction details
virtualenv .venv
.\.venv\Scripts\activate
python -m pip install -U pip
pip install keyring artifacts-keyring
pip install as-api
This link was used to produce a pipeline to publish the package and the suggested way of installing the package. My approach is now a mix of both option 1 and option 2. Note the use of a php.ini file to set --index-url and the artifacts-keyring package (installing with --pre does not make any difference to the version), so it really doesn't make any difference. However, I have tried both options separately, it doesn't spawn a browser, so it gives the same result.
System details:
OS: Windows 10
Python 2.7.17
pip list
Package Version
----------------- ----------
artifacts-keyring 0.2.8rc0
certifi 2019.11.28
chardet 3.0.4
configparser 4.0.2
entrypoints 0.3
idna 2.8
keyring 18.0.1
pip 19.3.1
pywin32-ctypes 0.2.0
requests 2.22.0
setuptools 42.0.2
urllib3 1.25.7
wheel 0.33.6
Folder structure:
test
|-- test.py
|-- .venv
|-- pip.ini
|-- ... other virtualenv folders and files
pip.ini:
[global]
extra-index-url = https://pkgs.dev.azure.com/company/company_Software/_packaging/PyPI/pypi/simple/
Further analysis
Using a clean laptop actually works with the above reproduction details. Other computers in the company also have the same problem, so some of our set up is conflicting with the authentication.
If we use a pipeline (see this link) to install the as-api package, it works, so I suspect this is an authentication problem, but it's not mentioned on any documentation.
Using https://username:password#... does not give any authentication error, even with wrong username and password.
Using the correct username but have symbols in the password triggers interactive mode to enter username and password. However, this gives this error: WARNING: 401 Error, Credentials not correct for https://pkgs.dev.azure.com/company/company_Software/_packaging/PyPI/pypi/simple/as-api/ Note that I am the owner of the Artifacts feed and the team has been added as the owner in the permission tab.
As a workaround:
Looks like you're using option2 from the document to do the install. I happen to see one similar issue which indicates this error message could have something to do with pip.ini(windows) or pip.conf(linux/mac), so I think you can try another approach to avoid something wrong with those configurations.
You can run pip install artifacts-keyring --pre and then run
pip install packageName --index-url https://pkgs.dev.azure.com/xxx/xxx/_packaging/xxx/pypi/simple/ -vvv --no-deps
You would meet something like this when running command pip install artifacts-keyring --pre:
After the login-in passes, you would get the package you need if it do exist in your feed.
Assuming your Azure DevOps artifacts is private and you have a PAT then installing a package from the artifact can be done in the following two ways
If you have access to a terminal (only preferred in dev environment)
pip install https://<your-feed-name>:<your-PAT-key>#pkgs.dev.azure.com/<your-organization-name>/<your-project-name>/_packaging/<your-feed-name>/pypi/simple/ Your-Package-Name==x.x.x
Note: All the names (eg: feed, project) must follow the HTTPS URL convention.A simple (& actually correct) way to get to know the URL is goto Artifacts --> Select your artifact feed --> Connect to feed --> PIP --> Here you will get the correct URL. Also, use the some feed name both the place in URL
Using requirements.txt (this will be ideally used in prod or CI/CD pipeline) and automating the process:
Mind you it need a bit of string/URL manipulation. Add the respective line/URL in your requirements.txt in following manner:
The URL will be mostly similar to the earlier URL used in the earlier terminal method
In the URL after simple everything will have to change, modified URL-
https://<your-feed-name>:<your-PAT-key>#pkgs.dev.azure.com/<your-organization-name>/<your-project-name>/_packaging/<your-feed-name>/pypi/download/<yourpackagename>/<package version>/Your-Package-Name.whl
#assuming your package is a .whl file
So simple changed to download; then whatever is your package name, whether it contains '-' or '_' or CAPS, everything will be removed and converted into small case.
Next is version no of your package that you want to install & finally the name of wheel or .whl file.
My issue was that I had not installed artifacts-keyring. After that I could see VS Code authenticating to the feed and installing the package.
I also needed to upgrade pip (needs to be above > 19.2) with the following command:
python -m pip install --upgrade pip
The fix
Do one of the following:
Remove the VSS_NUGET_EXTERNAL_FEED_ENDPOINTS environment variable (not very useful, not recommended).
Add an extra endpoint to the VSS_NUGET_EXTERNAL_FEED_ENDPOINTS environment variable. E.g.,
{"endpointCredentials": [{"endpoint":"https://pkgs.dev.azure.com/company/_packaging/NuGetFeed/nuget/v3/index.json", ...},{"endpoint":"https://pkgs.dev.azure.com/company/company_Software/_packaging/PyPI/pypi/simple/", ...}]}
We have a script which sets up these endpoints, so this turns out to be a simple fix.
The cause
It turns out that if you have used artifacts-credprovider to set up another feed, in our case, a NuGet feed with another endpoint, the VSS_NUGET_EXTERNAL_FEED_ENDPOINTS environment variable stores only that feed URL inside the key endpoint. artifacts-keyring will still read that environment variable even if the endpoint doesn't exist, which causes authentication problem. The -vvv log doesn't tell you anything about authentication and it won't attempt to authenticate using another method.
As an update to #user:10097045 's answer
You must add the --extra-index-url= infront of the URL with path in option 1 otherwise pip will fail to find the directory
Otherwise answer was super helpful you just get a 404 without that definition

How to install a predefined package(class) in google colab(python,Jupyter notebook)?

I have already defined a class which I want to use in my code.
in order to import it I know I have to install it first.(I am using google's colab)
to install first I uploaded the .py file into my drive which is mounted and no problem with that.
but still there is problem with installing the package.
how can I use this predefined class correctly in my code?
!pip install robotdef.py
Collecting robotdef.py
ERROR: Could not find a version that satisfies the requirement robotdef.py (from versions: none)
ERROR: No matching distribution found for robotdef.py
I think I overlooked one thing.
If "I uploaded the .py file into my drive which is mounted and no problem with that." is the situation, you don't have to run pip, but you'll need to expand the Python path to the directory where your package(class) is installed.
I hope this may help.
import sys
sys.path.append('/foo/bar/your-modules-path')
pip fetches a package from the Python Package Index (PyPI) repository. This means that the package must be registered on the repository first.
I tried to find 'robotdef.py' or 'robotdef' using a search form on the PyPI website, but it seems that 'robotdef.py' hasn't been registered yet...
If it's on the repository, !pip install <package name> will work fine on the Colab.
Supplement
Sorry, my answer was incomplete.
It's not necessary a package to be registered on the PyPI repository, but you can install a package from local archives, etc.

Why upload module in repository not found via pip install?

I upload module
example-framework.python.egg
via Jenkins in JFrog Artifactory.
Upload completed good without errors.
I checked in Artifactory, in repository browser saw in properties
pypi.name - example-framework
Tried to install module via artifactory.
pip install example-framework
pip returned error:
Collecting example-framework
Could not find a version that satisfies the requirement example-framework (from versions: )
No matching distribution found for example-framework
How solve this problem?
For the user running pip, make sure you have correctly setup your ~/.pip/pip.conf file to point to Artifactory. You can see an example of this in the Set Me Up box for the pipy repo.

Python: Install Dependencies into directory

I have a Python project that I want to get worked in Amazon aws Lambda. So i need to creat a deployment package. I tried it like explained on this page:
http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html
But here my problem:
Some Dependencies I can install, some are not installable.
If I want to install requests into a directory, It installs. If I want to install json into a directory I get the following error massage: Directory '/Users/iTom/Desktop/project-dir' is not installable. File 'setup.py' not found.
Dont know if this is important: I tried also to install json in general an got this error: Could not find a version that satisfies the requirement json (from versions: )
No matching distribution found for json
Thanks for help :)
EDIT: I got told json already included. What is with codecs and urllib?
json is a built-in package already shipped with python, you need not install it. Please see the python reference https://docs.python.org/2/library/json.html

Categories

Resources