1

I am trying to run a ping using windows powershell, but this is the result:

ping google.com
Traceback (most recent call last):
  File "C:\Program Files\Python36\Scripts\ping.py", line 31, in <module>
    from impacket import ImpactDecoder, ImpactPacket
ImportError: No module named impacket

It seems that a python ping command is trying to be executed instead of the windows default ping command. How can I solve this?

PATH:

$env:PATH.split(";")
C:\Program Files\Python36\Scripts\
C:\Program Files\Python36\
C:\Program Files\Python37\Scripts\
C:\Program Files\Python37\
C:\Program Files\AdoptOpenJDK\jre-8.0.212.03-hotspot\bin
C:\Program Files (x86)\AdoptOpenJDK\jre-8.0.212.03-hotspot\bin
C:\Program Files\AdoptOpenJDK\jre-11.0.3.7-hotspot\bin
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\WINDOWS\System32\OpenSSH\
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL
C:\Program Files\Intel\WiFi\bin\
C:\Program Files\Common Files\Intel\WirelessCommon\
C:\Program Files\PuTTY\
C:\Program Files (x86)\Intel\Intel(R) Memory And Storage Tool\
C:\Users\user\AppData\Local\Microsoft\WindowsApps

C:\Program Files\JetBrains\PyCharm 2020.1\bin

C:\texlive\2019\bin\win32
C:\Program Files (x86)\Nmap
C:\Program Files\Intel\WiFi\bin\
C:\Program Files\Common Files\Intel\WirelessCommon\
3
  • 1
    Without fixing the underlying problem you can specify the full path to the ping command to bypass the python script C:\Windows\system32\ping.exe google.com. Without seeing your working directory and PATH environment variable it's difficult to understand what you've done wrong. Since you use PowerShell please update your post with the output from $env:PATH.split(";").
    – megamorf
    Commented Dec 2, 2020 at 12:06
  • @megamorf I added the PATH
    – Ale1794
    Commented Dec 2, 2020 at 12:09
  • Please make sure to mark the answer as accepted if it has solved your problem :-)
    – megamorf
    Commented Dec 2, 2020 at 12:47

1 Answer 1

3

Issue analysis

Your problem is that Windows goes through each entry in the PATH variable and checks if a binary of the name you're calling exists in there and aborts the search on the first match. Since your PATH variable contains the Python Scripts entries before the common Windows paths they'll override default commands since they contain a script called ping.

It's uncommon to add custom paths to the beginning of the PATH variable. You usually append to its end.

How to fix:

Take the list above and combine all entries with ; as delimiter. But make sure to move the following entries to the end of the list:

C:\Program Files\Python36\Scripts\
C:\Program Files\Python36\
C:\Program Files\Python37\Scripts\
C:\Program Files\Python37\
C:\Program Files\AdoptOpenJDK\jre-8.0.212.03-hotspot\bin
C:\Program Files (x86)\AdoptOpenJDK\jre-8.0.212.03-hotspot\bin
C:\Program Files\AdoptOpenJDK\jre-11.0.3.7-hotspot\bin

Then follow these steps to update the PATH variable:

  1. On the Windows desktop, right-click My Computer.
  2. In the pop-up menu, click Properties.
  3. In the System Properties window, click the Advanced tab, and then click Environment Variables.
  4. In the System Variables window, highlight Path, and click Edit.
  5. In the Edit System Variables window, replace the list with your prepared list of entries (the full list from your post, reordered, with semicolons as delimiters). If the last character is not a semi-colon (;), add one.

Finally reboot the computer to ensure that all programs use the updated PATH variable.

Edit

It seems in Windows 10 they updated the PATH editor so that when you edit the variable you get a little editor window that allows you to edit each entry separately and also allows you to move them up and down. Simply move the Python entries to the bottom of the list.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .