winshell.shortcut(parent) giving 'module has no attribute 'shortcut'

180 views Asked by At

-Update at the bottom-

pywin32 & winshell installed with no apparent errors, but the following test code (extracted from the example here: winshell examples ):

import winshell
parent = 'H:\MUSIC\TESTC\TESTTB.lnk'  # target is H:\MUSIC\TESTB
with winshell.shortcut(parent) as link:
    print(link.path)

produced this result:

> Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
Traceback (most recent call last):
  File "C:\Python33\MyScripts\Audio\shortcut2.py", line 3, in <module>
    with winshell.shortcut(parent) as link:
AttributeError: 'module' object has no attribute 'shortcut'
>>> 

Presumably something must, in fact, not be right with the winshell install - what should I be looking for?

PS: The system seems to require the output on the python window to be formatted as code which it clearly is not. Curious as to why. It does contain a code fragment but that's not the same thing.

  • update - Most of the other methods shown in the docs are not in the dir(winshell) output (eg the file methods such as copy_file):

    >>> dir(winshell)
    >>> ['__RELEASE__', '__VERSION__', '__builtins__',  
    >>> '__cached__', '__doc__', '__file__', 
    >>> '__initializing__', '__loader__', '__name__', 
    >>> '__package__', '__path__']
    
1

There are 1 answers

0
RFlack On

Problem solved after some assistance from @Maksim Yegorov. The problem was that the installation process automatically put the winshell files into .../Lib/site-packages/winshell.
However for the example code to work they need to be in .../Lib/site-packages If they are to be in their own folder then instead of
from winshell import shortcut its from winshell.winshell import shortcut and line 26 of winshell.py needs to be modified in like manner to from winshell.__winshell_version__ import __VERSION__

The winshell docs may need to be clarified to avoid this.