

poewrshellを使って、Data Visualizationを学びはじめた者です。  
Pythonのversionは2.7  
windowsは8.1を使用しています。

私の、システム環境変数パスは、下記の通りです。

[code]

    c:\python27\;c:\python27\scripts;c:\python27\tools\scripts;C:\Program Files (x86)\Common Files\Apple\Apple Application Support;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;C:\Program Files (x86)\Roxio 2010\OEM\AudioCore\;C:\Program Files (x86)\Brackets\command;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Git\bin;C:\Program Files (x86)\Git\cmd
    
[/code]

現在、基本的に（<http://newcoder.io/begin/setup-your-
machine/#windows>）のガイダンスに沿って、コンピューター環境を整えている状態です。  
powershell, python, git, pip, virtualenv, virtualenvwrapper-
powershellのインストールは（助けてもらいながら）順調に進んだのですが、  
type:`Import-Module virtualenvwrapper` という所でスタックしてしまいました。。（virtualenvwrapper-
powershellのインストールは完了しています。。）

私が、`Import-Module virtualenvwrapper`と入力すると、以下のエラーメッセージが得られます。

[code]

    PS C:\python27> Import-Module virtualenvwrapper
    Import-Module : The specified module 'virtualenvwrapper' was not loaded because no valid module file was found in any
    module directory.
    At line:1 char:1
    + Import-Module virtualenvwrapper
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ResourceUnavailable: (virtualenvwrapper:String) [Import-Module], FileNotFoundException
        + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
    
[/code]

また、モジュールを、そのモジュールと同じ名前のフォルダに保存するか、.psm1をコマンドに使うと上手くいくかもしれないよ。とのご指摘を頂き、((<https://stackoverflow.com/questions/31096527/import-
module-virtualenvwrapper/31097136#31097136>))

[code]

    C:\Python27\virtualenvwrapper
    
[/code]

に`virtualenvwrapper.psm1`を配置し、  
`Import-Module virtualenvwrapper`を実行してみましたが、エラーメッセージは上記と同じでした。。

[code]

    Import-Module : The specified module 'virtualenvwrapper' was not loaded because no valid module file was found in any
    module directory.
    At line:1 char:1
    + Import-Module virtualenvwrapper
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ResourceUnavailable: (virtualenvwrapper:String) [Import-Module], FileNotFoundException
        + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
    
[/code]

また、`Import-Module virtualenvwrapper.psm1`も実行してみましたが、以下のエラーメッセージが得られました。。。

[code]

    Import-Module : The specified module 'virtualenvwrapper.psm1' was not loaded because no valid module file was found in
    any module directory.
    At line:1 char:1
    + Import-Module virtualenvwrapper.psm1
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ResourceUnavailable: (virtualenvwrapper.psm1:String) [Import-Module], FileNotFoundExcept
       ion
        + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
    
[/code]

また、 `Import-Module C:\Python27\virtualenvwrapper\virtualenvwrapper.psm1`
も実行してみましたが、以下のエラーメッセージが得られました。。。

[code]

    PS C:\python27>  Import-Module C:\Python27\virtualenvwrapper\virtualenvwrapper.psm1
    Import-Module : The specified module 'C:\Python27\virtualenvwrapper\virtualenvwrapper.psm1' was not loaded because no
    valid module file was found in any module directory.
    At line:1 char:2
    +  Import-Module C:\Python27\virtualenvwrapper\virtualenvwrapper.psm1
    +  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ResourceUnavailable: (C:\Python27\vir...envwrapper.psm1:String) [Import-Module], FileNot
       FoundException
        + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
    
[/code]

また、このページを参考に（<https://stackoverflow.com/questions/31035903/installing-
virtualenvwrapper-powershell-in-windows-8-1-import-module-failing>）、  
`WindowsPowerShell\Modules` というフォルダーをドキュメントに作成し、（the virtualenvwrapper-
powershell bitbucket ）からとってきた、`VirtualEnvWrapper` ディレクトリを  
Modulesフォルダに設置し、`Set-ExecutionPolicy Unrestricted` を実行してから`Import-Module
virtualenvwrapper`を実行したのですが、やはりエラーとなりました。。

エラーメッセージは以下の通りです。

[code]

    PS C:\python27> Set-ExecutionPolicy Unrestricted
    
    Execution Policy Change
    The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
    you to the security risks described in the about_Execution_Policies help topic at
    http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
    [Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
    PS C:\python27> Import-Module virtualenvwrapper
    Import-Module : The specified module 'virtualenvwrapper' was not loaded because no valid module file was found in any
    module directory.
    At line:1 char:1
    + Import-Module virtualenvwrapper
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ResourceUnavailable: (virtualenvwrapper:String) [Import-Module], FileNotFoundException
        + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
    
[/code]

長々と申し訳ございませんでした。  
どなたか、何かアイデアのございます方、お力を貸して頂けますと助かります。。

★追記★  
BLUEPIXY様へ、下記新たなエラーメッセージとなります。。

[code]

    PS C:\windows\system32> Import-Module virtualenvwrapper
    
    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run
    C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1?
    [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): r
    At C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1:48 char:3
    + if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ]
    +   ~
    Missing '(' after 'if' in if statement.
    At C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1:48 char:5
    + if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ]
    +     ~
    Missing type name after '['.
    At C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1:54 char:3
    + if [ "$VIRTUALENVWRAPPER_VIRTUALENV" = "" ]
    +   ~
    Missing '(' after 'if' in if statement.
    At C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1:54 char:5
    + if [ "$VIRTUALENVWRAPPER_VIRTUALENV" = "" ]
    +     ~
    Missing type name after '['.
    At C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1:59 char:38
    + virtualenvwrapper_derive_workon_home() {
    +                                      ~
    An expression was expected after '('.
    At C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1:64 char:7
    +     if [ "$workon_home_dir" = "" ]
    +       ~
    Missing '(' after 'if' in if statement.
    At C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1:64 char:9
    +     if [ "$workon_home_dir" = "" ]
    +         ~
    Missing type name after '['.
    At C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1:71 char:7
    +     if echo "$workon_home_dir" | (unset GREP_OPTIONS; \grep '^[^/~]' > /dev/null ...
    +       ~
    Missing '(' after 'if' in if statement.
    At C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1:71 char:53
    +     if echo "$workon_home_dir" | (unset GREP_OPTIONS; \grep '^[^/~]' > /dev/null ...
    +                                                     ~
    Missing closing ')' in expression.
    At C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1:71 char:34
    +     if echo "$workon_home_dir" | (unset GREP_OPTIONS; \grep '^[^/~]' > /dev/null ...
    +                                  ~~~~~~~~~~~~~~~~~~~
    Expressions are only allowed as the first element of a pipeline.
    Not all parse errors were reported.  Correct the reported errors and try again.
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : MissingOpenParenthesisInIfStatement
    
    Import-Module : The specified module 'virtualenvwrapper' was not loaded because no valid module file was found in any
    module directory.
    At line:1 char:1
    + Import-Module virtualenvwrapper
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ResourceUnavailable: (virtualenvwrapper:String) [Import-Module], FileNotFoundException
        + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
    
[/code]

★追追記★

以下が、新しいエラーメッセージとなります。。  
だいぶエラーメッセージが、短くなりました！！

[code]

    PS C:\windows\system32> Import-Module virtualenvwrapper
    
    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run
    C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1?
    [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): r
    Switch-DefaultPython : The term 'Switch-DefaultPython' is not recognized as the name of a cmdlet, function, script
    file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
    and try again.
    At C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1:16 char:1
    + Switch-DefaultPython
    + ~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Switch-DefaultPython:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    
    Initialize : The term 'Initialize' is not recognized as the name of a cmdlet, function, script file, or operable
    program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1:334 char:1
    + Initialize
    + ~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Initialize:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    
[/code]

★追追追記★

下記、エラーメッセージ  
メッセージがら見るに、いろんなものが自動化されていないようですね。。

[code]

    PS C:\windows\system32> Import-Module virtualenvwrapper
    
    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run
    C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1?
    [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): r
    
    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\Win\Win.psm1?
    [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): r
    Initialize : The term 'Initialize' is not recognized as the name of a cmdlet, function, script file, or operable
    program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1:334 char:1
    + Initialize
    + ~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Initialize:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    
[/code]

★＠追記★  
遂に成功したかのように見えます。以下のメッセージの様に、今回のエラーは、『TabExpansion』によるものだけで、これは無視してよいエラーみたいです！  
ということは、今回の”Import-Module virtualenvwrapper”の実行は、成功かと思います。  
しかし、メッセージ中に、何も『成功』形跡がありません。。  
これは本当に成功したのでしょうか。。

[code]

    PS C:\windows\system32> Import-Module virtualenvwrapper
    
    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\support.psm1?
    [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): r
    
    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\win.psm1?
    [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): r
    
    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run
    C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\VirtualenvWrapperTabExpansion.psm1?
    [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): r
    Get-Content : Cannot find path 'Function:\TabExpansion' because it does not exist.
    At C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\VirtualenvWrapperTabExpansion.psm1:12
    char:21
    + $_oldTabExpansion = Get-Content Function:TabExpansion
    +                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Function:\TabExpansion:String) [Get-Content], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
    
    
    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run
    C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\virtualenvwrapper.psm1?
    [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): r
    
    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run
    C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\Extensions\Extension.Project.ps1?
    [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): r
    
    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run
    C:\Users\SomaSoma\Documents\WindowsPowerShell\Modules\virtualenvwrapper\Extensions\Extension.UserScripts.ps1?
    [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): r
    PS C:\windows\system32>
    
[/code]

また、`Get-Command *virtualenv*`

を実行すると、下記の様に表示され、やはり成功したかのように見えます。

[code]

    PS C:\windows\system32> Get-Command *virtualenv*
    
    CommandType     Name                                               ModuleName
    -----------     ----                                               ----------
    Alias           cdvirtualenv ->                                    VirtualEnvWrapper
    Alias           cpvirtualenv ->                                    VirtualEnvWrapper
    Alias           lsvirtualenv ->                                    VirtualEnvWrapper
    Alias           mkvirtualenv ->                                    VirtualEnvWrapper
    Alias           rmvirtualenv ->                                    VirtualEnvWrapper
    Function        add_posh_to_virtualenv                             VirtualEnvWrapper
    Function        add2virtualenv                                     VirtualEnvWrapper
    Function        CDIntoVirtualEnvironment                           VirtualEnvWrapper
    Function        Copy-VirtualEnvironment                            VirtualEnvWrapper
    Function        GetVirtualEnvCompletions                           VirtualEnvWrapper
    Function        GetVirtualEnvData                                  VirtualEnvWrapper
    Function        Get-VirtualEnvironment                             VirtualEnvWrapper
    Function        LetVirtualEnvsThru                                 VirtualEnvWrapper
    Function        LooksLikeAVirtualEnv                               VirtualEnvWrapper
    Function        NewVirtualEnvData                                  VirtualEnvWrapper
    Function        New-VirtualEnvironment                             VirtualEnvWrapper
    Function        Remove-VirtualEnvironment                          VirtualEnvWrapper
    Function        Set-VirtualEnvironment                             VirtualEnvWrapper
    Function        showvirtualenv                                     VirtualEnvWrapper
    Application     add2virtualenv.bat
    Application     cdvirtualenv.bat
    Application     lsvirtualenv.bat
    Application     mkvirtualenv.bat
    Application     rmvirtualenv.bat
    Application     virtualenv.exe
    Application     virtualenv-3.4.exe
    Application     virtualenv-clone.exe
    
[/code]


CC BY-SA 3.0
2015-06-28T14:11:38.773
11830
2016-10-13T16:01:44.327
2017-05-23T12:38:55.307
-1
10314
question
python powershell
powershell を使って　Import-Module virtualenvwrapper の実行


モジュールを置く場所はモジュールパスで示される場所になければいけません。  
標準のスクリプトモジュールのユーザーレベル(ユーザー毎のモジュール)パスは  
`C:\Users\UserName\Documents\WindowsPowerShell\Modules`  
です。(UserNameは、それぞれのユーザー名）  
そういう意味で、モジュールを置く正しいディレクトリは最後のやつです。  
つまりドキュメントフォルダにWindowsPowerShell\Modulesフォルダを作り  
Modulesフォルダにモジュール名のフォルダ`virtualenvwrapper.psm1`の場合は`virtualenvwrapper`フォルダを作りそこに`virtualenvwrapper.psm1`ファイルを置きます。  
それで、  
`Import-Module virtualenvwrapper`を実行すればいいかと思います。  
(バージョン３以降は起動時に自動読込されるはず）


CC BY-SA 3.0
2015-06-28T15:11:42.747
11831
2015-06-28T15:11:42.747
5044
11830
answer