I have a working python 3.7.3 (Anaconda) and configured iis 10 on windows 10
I address the following script via http://127.0.0.1/py3/hw.py
This works without error so modules can be imported
import sys
print('Content-Type: text/html')
print('')
print('Hello, world! ')
but the following does not work using http://127.0.0.1/py3/hw.py, claiming that the module numpy can't be located
though running it from the Anaconda command prompt does work
import sys
import numpy
print('Content-Type: text/html')
print('')
print('Hello, world! ')
I presume there is a path issue here
I have tried adding the Anaconda path additions to the standard windows path which does not work
Any suggestions most welcome
I made some test on my local and it is working fine.
1.I installed numpy via command line: pip install numpy==1.17.3
2.Please ensure your authenticated user like NT Authority/IUSR have enough permission to access your python's lib folder.
It is recommended to troubleshooting this issue with Microsoft Process monitor and scan access denied error inside w3wp.exe or python.exe.
https://learn.microsoft.com/en-us/sysinternals/downloads/procmon
Related
I am trying to make a nmap scanner for the InfoSec Certification on freeCodeCamp.org and cannot get Visual Studio Code to recognize that I have installed nmap. I am very beginner and in the process of learning.
from cProfile import run
import nmap
scanner = nmap.PortScanner()
print("Welcome, this is a simple automattion tool")
print("<------------------------------------------->")
When I run this in VS Code I get the following in the terminal:
PS C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1> python3 scanner.py
Traceback (most recent call last):
File "C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1\scanner.py", line 2, in <module>
import nmap
ModuleNotFoundError: No module named 'nmap'
PS C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1>
I have so far:
Updated to the current Python 3.10.7
Installed Nmap the first time from https://nmap.org/ for Windows
Uninstalled Nmap
Reinsalled Nmap using >>>pip3 install python-nmap
For future searchers (as in my comment above), if you installed a module with pip3 but are still getting module import errors, try python3 -m pip install <module-name>.
Not sure how/why this happens (pip3 installing somewhere that python3 is not looking for modules - maybe PYTHONPATH-related), but the above can [usually] help.
It seems that Python cannot find nmap module.
You can either add it to path in Windows via Start -> Edit system environment variables -> Environment variables... and then edit PATH VARIABLE by adding at the end path to nmap module that you have installed or move the module to default Python modules directory which should be C:\Users\YourLogin\AppData\Local\Programs\Python\Python310\Lib\site-packages
Folks, I am having this puzzle with a pybind11 library mytest.cp37-win_amd64.pyd put in C:\Temp.
Then I have this:
import sys
sys.path.insert(0, r"C:\Temp")
from mytest import *
Now here comes the problem, if I launch the python in command line:
>python
>>>import sys
>>>sys.path.insert(0, r"C:\Temp")
>>>from mytest import *
It works fine. Or I just put above code in test.py, then run:
>python test.py
It also works. If I put this piece of code in Spyder, it works as well. But if I put this piece of code in Jupyter, it will not work by saying:
ModuleNotFoundError: No module named 'mytest'
I am sure all my tests are conducted in the same python environment by printing it out:
import os
print(os.environ['CONDA_DEFAULT_ENV'])
Am I missing anything here?
With Wayne's help and a previous post, I finally found out the root cause, that is the version of the python running in the Jupyter kernel is different from that of the environment from which the Jupyter is launch and also the pybind11 library is build with.
After I reinstall the Jupyter in the environment again, the library is picked up successfully.
I get ImportError: no module named Flopy when I try to run the following script from an Anaconda prompt in the folder that the script it stored in, but when I run the script through Spyder it imports Flopy just fine and the rest of the code (not shown) which uses Flopy also works.
# import the required libraries
try:
import flopy
except:
fpth = os.path.abspath(os.path.join('..', '..'))
sys.path.append(fpth)
import flopy
The Spyder ran version never runs the code under than 'except' section since it managed to import Flopy at first try. I tried checking the path created by os.path.abspath(os.path.join('..', '..')) and even copied the Flopy directory to that location and running the script from the Anaconda prompt started in that folder...which did make some difference, but the import failed with error: ImportError: cannot import name getfullargspec.
Any ideas why imports work one way but not the other?
Fixed it with help from #Jainal Patel! I just had to tidy up all my environment paths. There was an installed version of Python in C:\Python3, but Spyder was using the one in C:ProgramData\Anaconda.
Now when I open the command prompt, or an Anaconda prompt, or use Spyder, it uses the same Python environment and recognizes all my installed packages.
!pip install flopy
try:
import flopy
except:
fpth = os.path.abspath(os.path.join('..', '..'))
sys.path.append(fpth)
import flopy
you need to install it first either using pip or conda
I am using python3.
I installed twython on my MAC using pip3 command and I confirmed it was successfully installed.
When I run my python file, it comes up with:
ImportError : No module named twython
My code is as follows:
import sys
import string
import json as simplejson
from twython import Twython
I can't comment the response from #ajxs, but as additional information to his repsonse:
You can change the default python interpreter like this in your MAC terminal:
nano ~/.bash_profile
Add this to the file:
alias python=python3
exit the the bashrc file and run the following command:
source ~/.bash_profile
Now you can check the defaul python version with:
python --version
Maybe this helps you.
First thing that springs to mind is to check that you're running the script with the correct version of Python. Use python --version on the command line to check which version of Python you're executing by default. I've definitely had problems like this before when I've forgotten that my system's default version was 2.7 and I needed to use python3 to run Python 3 on the command line.
I am trying to set up IBPY and Python on my Mac to run with Interactive Brokers. I have installed Git. I created a subdirectory ibapi under Home. I downloaded IBPy using git clone https://github.com/blampe/IbPy from the ibapi directory.
I am now trying to run the Demo.py program in Spyder. When I choose Run, I receive the error message:
ImportError: No module named Ib.Message
The first few lines of the demo program are:
import os
import sys
import time
import Ib.Message
import Ib.Socket
import Ib.Type
I am also trying to run a sample program: ib_api_demo from http://www.quantstart.com/articles/Using-Python-IBPy-and-the-Interactive-Brokers-API-to-Automate-Trades. When I try to run this, I get the error message:
ImportError: No module named ib.ext.Contract
The first few lines are:
from ib.ext.Contract import Contract
from ib.ext.Order import Order
from ib.opt import Connection, message
I figured this out. The problem was I was launching Spyder from my Mac Finder. When I did this, I received the error messages. When I launched Spyder (actually Anaconda Python) by typing "Spyder" in the Terminal window, this launched Anaconda Python. From here, I could run all my programs successfully with no errors.