简体   繁体   中英

File association not found for extension .py

I am having trouble executing my anaconda python

It seems python is not associated correctly or not at all

I do not have admin rights as this is a work computer and going through IT takes forever

My anaconda is located in the C:\\Users\\dean.lemcke-evans\\AppData\\Local\\Continuum\\anaconda3

Here is the error I am getting how do I fix it?

代码

To fix “File association not found for extension .py” on Windows, execute the following two commands in a cmd.exe with administrator privileges:

assoc .py=pyautofile
ftype pyautofile="C:\Anaconda2\python.exe" "%1" %*

Obviously edit the python.exe path above to where python.exe is found on your machine.

Reference: https://acloud.guru/forums/aws-dynamodb/discussion/-KWReio_6iBZoNMR4yoA/this-is-actually-an-answer-to-a-question-i-had-about-awscli-install-on-windows

I had to do the following (just another precursor to the above solution).

  1. Hit windows key and type cmd

  2. Right click on the cmd icon and choose run as an administrator

  3. Click on more choices (this is what is missing above)

  4. Enter the admin credentials.

  5. Copy paste the following and hit enter.

    assoc .py=pyautofile ftype pyautofile="C:\\Anaconda2\\python.exe" "%1" %*

If you want to execute this as python script below is the way. sys.executable will get python executable physical path, irrespective of os.

import sys

config_cmd= f'  ftype py_auto_file="{sys.executable}" "%1" %*' + '; assoc .py=py_auto_file '
config_cmd_out = subprocess.call(config_cmd, shell=True)
 if command_output == 0:
        logger.info(f'Success {command}')
    else:
        logger.error(f'Problem {command}')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM