Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Python 2, upgrading from 0.1.0b10 to 0.1.0b11 may cause 'KeyError: Azure' error #1540

Closed
derekbekoe opened this issue Dec 13, 2016 · 13 comments

Comments

@derekbekoe
Copy link
Member

On Python 2, it's recommended to upgrade with the --ignore-installed flag:
pip install --upgrade --ignore-installed azure-cli.

If the above isn't followed, KeyError may appear as pip fails to install 2 required files.
Add these manually with:

touch <path_to_site_packages>/azure/cli/__init__.py
touch <path_to_site_packages>/azure/cli/command_modules/__init__.py

<path_to_site_packages> is the path to the environment the CLI was installed into.
For example /usr/local/lib/python2.7/site-packages.

This is a one-time change.

Fresh installs are not affected.


More info:

Upgrading from the previous version of the CLI to this version breaks on Python 2.
It breaks because pip attempts to uninstall the old version first so #1406 occurs again.
Python 3 works because of implicit namespace package support.

@dtzar
Copy link

dtzar commented Dec 14, 2016

I believe I'm also experiencing this now after the upgrade. I get this when I type az:
Traceback (most recent call last): File "/usr/local/az/lib/python2.7/site.py", line 703, in <module> main() File "/usr/local/az/lib/python2.7/site.py", line 683, in main paths_in_sys = addsitepackages(paths_in_sys) File "/usr/local/az/lib/python2.7/site.py", line 282, in addsitepackages addsitedir(sitedir, known_paths) File "/usr/local/az/lib/python2.7/site.py", line 204, in addsitedir addpackage(sitedir, name, known_paths) File "/usr/local/az/lib/python2.7/site.py", line 173, in addpackage exec(line) File "<string>", line 1, in <module> KeyError: 'azure'

Going through the install again also does not fix the problem.

@nzthiago
Copy link
Member

If you have python3 and pip3 installed you might need to do this before it works:
sudo pip3 install --upgrade --no-deps --force-reinstall azure-cli

@derekbekoe
Copy link
Member Author

@dtzar Running the following commands should resolve the issue.

touch /usr/local/lib/python2.7/site-packages/azure/cli/__init__.py
touch /usr/local/lib/python2.7/site-packages/azure/cli/command_modules/__init__.py

@dtzar
Copy link

dtzar commented Dec 15, 2016

@nzthiago pip3 wasn't installed, but I installed it and gave your command a try (with and without --upgrade) and the same using just pip and I get: Could not find a version that satisfies the requirement azure-cli (from versions: 0.1.0b4, 0.1.0b10, 0.1.0b9, 0.1.0b7, 0.1.0b8, 0.1.0b11, 0.1.0b11, 0.1.0b9, 0.1.0b10)

I also tried the recommend per release notes: pip install --upgrade --ignore-installed azure-cli which gives the same error as above.

@derekbekoe touch does touch: cannot touch ‘/usr/local/lib/python2.7/site-packages/azure/cli/__init__.py’: No such file or directory
I initially installed Azure-Cli using curl -L https://aka.ms/InstallAzureCli | bash and installed into default directory option provided (/home/myusername/lib/azure-cli). I tried this again to no avail. When I try to run az from /home/myusername/lib/azure-cli/bin, I get /usr/bin/python: No module named azure

@derekbekoe
Copy link
Member Author

derekbekoe commented Dec 15, 2016

@dtzar The error "Could not find a version that satisfies the requirement azure-cli" from pip usually means an old version of pip is installed. Run pip --version to confirm. The latest version is 9.0.1.

In #1540 (comment), the commands I provided were based off #1540 (comment) but it looks like those directories were deleted at some point so that's why that doesn't work.

Finally, the curl script is a good install option.
The correct az executable should be in /home/myusername/bin not /home/myusername/lib/azure-cli/bin.
So you can run it with /home/myusername/bin/az or if /home/myusername/bin is in your PATH, just az.

@dtzar
Copy link

dtzar commented Dec 31, 2016

I had the latest version as you mentioned of pip. Why are the default installation directories not what is recommended? I installed via curl again to the directory you mentioned and still to no avail. I'm going to just keep using the docker image. If you want to live troubleshoot, feel free to reach out to me inside MSFT.

@derekbekoe
Copy link
Member Author

Will do.

@derekbekoe
Copy link
Member Author

Closed as the issue is marked as FAQ and it's documented in our install troubleshooting doc - https://github.com/Azure/azure-cli/blob/master/doc/install_troubleshooting.md#upgrade-from-010b10-causes-keyerror-azure-error.

@dtzar
Copy link

dtzar commented Jan 5, 2017

thanks to @brusMX I got this working via these commands:
touch /usr/local/az/lib/python2.7/site-packages/azure/cli/command_modules/init.py
touch /usr/local/az/lib/python2.7/site-packages/azure/cli/init.py

I am using Windows 10 bash, so perhaps the issue is unique to this when doing a curl | bash install method.

@brusMX
Copy link

brusMX commented Jan 5, 2017

Also, just to point out that the error @dtzar is running into is by installing the Az Cli in Windows 10 with Ubuntu bash through this command:

curl -L https://aka.ms/InstallAzureCli | bash

That command is actually setting the contents of the python2.7/site-packages within the az folder inside the /usr/local folder instead of using /usr/local/lib/python2.7

@derekbekoe
Copy link
Member Author

@brusMX This is intended.
With the curl script, the CLI gets installed into its own virtual environment. This is so that our dependencies do not conflict with any other Python dependencies that are currently installed on the system.

In your case, the root of this virtualenv is /usr/local/az.

@derekbekoe
Copy link
Member Author

Also, previously the default location of this virtualenv was /usr/local/az and now it is ~/lib/azure-cli.

@brusMX
Copy link

brusMX commented Jan 5, 2017

I supposed so @derekbekoe
What I intended to communicate is that it was unclear to determine the root of the virtualenv. Especially from what you just communicated, the last version of the code says DEFAULT_INSTALL_DIR = os.path.expanduser(os.path.join('~', 'lib', 'azure-cli')) and not really /usr/local/az

So if anybody else runs into this issue, they could realize that their virtualenv could be different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants