ModuleNotFoundError: No module named 'scrapy' (Error happend in PyCharm) - python

I just create a new project in PyCharm, then try to run the command scrapy startproject filename. Then the error happened.
Traceback (most recent call last):
File "c:\users\管理员\appdata\local\programs\python\python38\lib\runpy.py", line 194, in
_run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\管理员\appdata\local\programs\python\python38\lib\runpy.py", line 87, in
_run_code
exec(code, run_globals)
File "C:\Users\administrator\AppData\Local\Programs\Python\Python38\Scripts\scrapy.exe\__m
ain__.py", line 4, in <module>
ModuleNotFoundError: No module named 'scrapy'
Before I created this project, I had found that the administrator name was in Simple Chinese. To avoid the further problem in other project, I modify the name from simply Chinese as well and the file name in C://users/管理员 (where I installed the Python) and in the Path in system environment variables.
Does this error happen because of modification of the name? Or is there any other default configuration in PyCharm I need to modify?

After searching from a website named CSDN, I found this method works for my problem. I just briefly describe how I handle that.Hope it will be helpful for other people who meet the similar problem.
The link: https://blog.csdn.net/weixin_39278265/article/details/82938270
I installed the scrapy under C://user/管理员/.../Python38/...
And yesterday after I installed scrapy, I found it doesn't work in Pycharm but, in MS-DOS, it worked. Some people told me the path with UTF-8 characters caused the problem. So I modified the path from UTF-8 characters to English characters.
Then I deleted all the path environmental variables of Python in System and modified the path environmental variables of Python in Users from UTF-8 characters to English Characters.
After that I opened the pip.exe, pip3.exe, scrapy.exe in ...python38/scripts/ by Notepad and modified the path in the same way I did above.
After that I opened the PyCharm then run the command scrapy startproject projectname,it worked as in CMD interface and showed:
You can start your first spider with:
cd sxh01
scrapy genspider example example.com

Related

How to access python scripts from Windows service

The problem: we wish to run an Azure Devops pipeline which contains a step that runs a python command "mkdocs" to generate documentation. However, the pipeline does not have access to this script.
How are you supposed to access python scripts inside a Windows Service?
Environment
The pipeline runs on a self hosted Windows agent (more info). This pipeline runs as a Windows Service, with a "Network Service" account. Important to note is that this account does not have access to the AppData folder, because it is not a user.
mkdocs is a python package installed using pip, which comes with a mkdocs.exe which we attempt to run in the pipeline. This package is normally installed under the user's AppData folder.
Attempt 1:
Simply adding C:\Users\[REDACTED]\AppData\Roaming\Python\Python310\Scripts to PATH. This gives the following expected output in the logs of the pipeline:
##[error]'mkdocs' is not recognized as an internal or external command, operable program or batch file.
This is not surprising since the pipeline does not have access to the [REDACTED] user's AppData folder.
Attempt 2:
Changing the installation directory of pip packages using either --target=c:/PythonScripts, or with the C:\Users\[REDACTED]\AppData\Roaming\pip\pip.ini file:
[global]
target = c:\PythonScripts
When running pip install mkdocs, it successfully installs it into c:/PythonScripts. We add the folder c:/PythonScripts/bin to the PATH. Now when we try to run mkdocs from the command line, we get the following error:
C:\Users\[REDACTED]>mkdocs
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\PythonScripts\bin\mkdocs.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'mkdocs'
Somehow it does find the mkdocs.exe because it is on the path, but it cannot load the module mkdocs because that's installed in another directory?
Attempt 3:
Simply installing in the AppData folder and copying the contents. This also didn't work since the module was again not found.
Attempt 4:
Running the service as the user. This is really really undesirable, but it works. I would like to know a proper solution to this problem.

ModuleNotFoundError: No module named 'binance.client'; 'binance' is not a package

Hey i am new to both Stack Over Flow and Python, but wanting to learn and hoping someone can assist me here.. I am trying to develop a binance trading bot within python. Please see my script below:
from binance.client import Client
class Trader:
def __init__(self, file):
self.connect(file)
""" Creates Binance client """
def connect(self,file):
lines = [line.rstrip('\n') for line in open(file)]
key = lines[0]
secret = lines[1]
self.client = Client(key, secret)
""" Gets all account balances """
def getBalances(self):
prices = self.client.get_withdraw_history()
return prices
filename = 'API credentials.txt'
trader = Trader(filename)
balances = trader.getBalances()
print(balances)
This script is giving me a module not found error please see full details below:
PyDev console: starting.
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
runfile('C:/Users/ryanf/PycharmProjects/trading bot/trader.py', wdir='C:/Users/ryanf/PycharmProjects/trading bot')
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm Edu 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm Edu 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/ryanf/PycharmProjects/trading bot/trader.py", line 1, in <module>
from binance.client import Client
File "C:\Program Files\JetBrains\PyCharm Edu 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'binance.client'; 'binance' is not a package
Hoping some one can offer some advice here, it would be very much appreciated.
Make sure you don't have any files named "binance" in the same folder - that's what happened to me.
Would recommend the docs: https://docs.python.org/3/reference/import.html These are very long docs, but here are the "highlights":
See docs on path entry finders. You can import sys; print(sys.path) before any import statement, and also check PYTHONPATH environment variable where you're running the script. If you know where your package or module is located, ensure that that location is listed from the statement above.
See docs on installing libraries/modules -- Assuming you have installed pip, did you run pip install python-binance at any point, and if you run pip list from the command line, is "binance" listed?
If binance is a subdirectory in current directory, you may be missing an __init__.py file -- See docs on packages.
When you change the PYTHONPATH or make other changes, beware of ambiguity; avoid creating multiple sources where a module might be coming from, and name your modules/packages in a way as to avoid shadowing an existing module. See documentation on precedence of search paths
I tried a lot of things already here on google but nothing was useful, then I tired pip install python-binance==0.7.5 instead of pip install python-binance==0.7.9, and I was successful to import " from binance.client import Client.
Beside this, I also renamed my two binance.py files as binance.client.py, and it worked for me.
You can find your binance.py files in your python3 site packages folder. Just go there and search binance.py, you will find it.
In my case the problem was resolved by using:
pip install python-binance
instead of:
pip install binance
Hope it helps someone.
by calling your file binance.py, and then trying to import from binance.client python is looking in your binance.py file.
If you rename your local file then you won't have an issue.
I encountered the same problem and found that it was because I have installed python twice from two different sources (python.org and Microsoft store). By changing the python source in the VS Code, the issue was solved.
I know this is an old question, but i have just encountered it, and here are all possible ways of solving the problem
Look up, if have name any file binance.py - rename it.
you might have installed it from 2 different sources (python2, python3)
You might need to update pip.
In case if you are using conda env, even if u have set your virtual env in that folder - you have to switch python version in conda itself.
Here is where it can be done is VScode

Openslide-python import error

I receive the following error when running import openslide from inside python terminal
<code>Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\dev_res\python\python2_713\lib\site-packages\openslide\__init__.py", line 29, in <module>
from openslide import lowlevel
File "C:\dev_res\python\python2_713\lib\site-packages\openslide\lowlevel.py", line 41, in <module>
_lib = cdll.LoadLibrary('libopenslide-0.dll')
File "C:\dev_res\python\python2_713\lib\ctypes\__init__.py", line 440, in LoadLibrary
return self._dlltype(name)
File "C:\dev_res\python\python2_713\lib\ctypes\__init__.py", line 362, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 127] The specified procedure could not be found
</code>
My OS is Windows 64-bit and I am using Python 2.7.13 (64-bit). I installed the OpenSlide binaries (2016-7-17 64-bit release) and added the corresponding bin folder to my system path. I then installed python-openslide using pip. Please note that this error is different from WindowsError: [Error 126] The specified module could not be found (see question) which occurs when the windows binaries have not been added to the system path.
Same problem occurs when using Python 3.5.3. Interestingly, I tried the same workflow except with the 32-bit versions (python 2.7 32-bit and 32-bit openslide binaries) and I did not receive this error. However, I would prefer to use the 64-bit versions.
Any help would be greatly appreciated. Thanks!
After receiving help from the openslide-python authors on github, I was able to get a working solution.
The problem is that there are multiple dll's in your search path with the same name as those required by openslide. In my case for example, zlib1.dll is not only found in the openslide\bin directory but also in a MATLAB directory, github directory, and an Intel wifi directory. When python asks the operating system to find the required dll, the operating system is going to return the first name-matching instance that it encounters which might not be the openslide\bin one.
A quick fix is to start python from inside the openslide\bin directory. In other words, start a command prompt, navigate to the openslide\bin directory, type "python" and now typing import openslide should work fine. This works because the directory from which python was started is searched first for matching dll's. A more rigorous solution that will prevent you from having to start the terminal every time from inside openslide\bin is to add the following to the beginning of lowlevel.py file (which can be found in Lib\site-packages\openslide directory of your python installation)
os.environ['PATH'] = "path-to-openslide-bin" + ";" + os.environ['PATH']
Note: Replace path-to-openslide-bin with the correct path
Every time you type import openslide lowlevel.py is run which tries to load the appropriate dll's. The above line of code adds the location of the dll's to the beginning of the environment path which ensures that this folder is at the top of the search hierarchy and will therefore be found before the other name-matching instances.
You can view the corresponding issue/user report on github here

Pycharm: Run manage task won't work if path contains space

I'm running Pycharm 2.6.3 with python 2.7 and django 1.5.1. When I try to run django's manage.py task from Pycharm (Tools / Run manage.py task), syncdb, for instance, I get the following:
bash -cl "/usr/bin/python2.7 /home/paulo/bin/pycharm-2.6.3/helpers/pycharm/django_manage.py syncdb /home/paulo/Projetos/repo2/Paulo Brito/phl"
Traceback (most recent call last):
File "/home/paulo/bin/pycharm-2.6.3/helpers/pycharm/django_manage.py", line 21, in <module>
run_module(manage_file, None, '__main__', True)
File "/usr/lib/python2.7/runpy.py", line 170, in run_module
mod_name, loader, code, fname = _get_module_details(mod_name)
File "/usr/lib/python2.7/runpy.py", line 103, in _get_module_details
raise ImportError("No module named %s" % mod_name)
ImportError: No module named manage
Process finished with exit code 1
If I run the first line on the console passing project path between single quotes, it runs without problems, like this:
bash -cl "/usr/bin/python2.7 /home/paulo/bin/pycharm-2.6.3/helpers/pycharm/django_manage.py syncdb '/home/paulo/Projetos/repo2/Paulo Brito/phl'"
I tried to format the path like that in project settings / django support, but Pycharm won't recognize the path.
How can I work in PyCharm with paths with spaces?
Thanks.
EDIT 1
PyCharm dont recognize path with baskslash as valid path either.
it's known bug http://youtrack.jetbrains.com/issue/PY-8449
Fixed in PyCharm 2.7
In UNIX you can escape whitespaces with a backslash:
/home/paulo/Projetos/repo2/Paulo\ Brito/phl
I had the same problem on ubuntu 18.4 LTS pycharm 2019.2.6.
I was trying to create a basic Django new project in folder 'Learing Django api' (my folder name had spaces in it). when I tried to run the server I got a error saying settings module not defined.
After spending few hours I realized pycharm was creating a seperate folder named 'Learning' in same directory.
I renamed my folder 'Learing Django api' to 'Learing_Django_api' and it worked.
I like pycharm but this folder insensitivity is insane.
Is it possible that you are taking in the argument with a space in it into a variable, then passing that to something that is seeing two arguments instead of one? If so, "requote" it before passing it along. Will you hit a point where that can't be corrected? If so, maybe the upgrade makes sense.

py2exe + pywin32 MemoryLoadLibrary import fail when bundle_files=1

I have created a simple program which uses pywin32. I want to deploy it as an executable, so I py2exe'd it. I also didn't want a huge amount of files, so I set bundle_files to 1 (meaning bundle everything together). However, when I attempt running it, I get:
Traceback (most recent call last):
File "pshelper.py", line 4, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "win32.pyc", line 8, in <module>
File "zipextimporter.pyc", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading win32ui.pyd
In my setup script, I tried doing packages=["win32ui"] and includes=["win32ui"] as options, but that didn't help. How can I get py2exe to include win32ui.pyd?
I don't have this problem if I don't ask it to bundle the files, so I can do that, for now, but I'd like to know how to get it to work properly.
Are you sure that the problem is that win32ui.pyd is not included? The stack trace isn't exactly the same as noted in the wiki, but check this out: http://www.py2exe.org/index.cgi/Py2exeAndWin32ui.
The work-around that has worked best so far is to simply re-implement the pywin32 functions using ctypes. That doesn't require another .pyd or .dll file so the issue is obviated.
Do care to try out PyInstaller? I've used it both on Windows 7 and Ubuntu 10.04 and it worked like magic, even when I compiled to .pyd on Windows.
I've been able to bundle all sorts of applications that I've developed with it.
I have the same problem trying to bundle psutil with py2exe. Here is what I found so far.
Traceback (most recent call last):
File "wx_gui.py", line 43, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "psutil\__init__.pyc", line 85, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "psutil\_psmswindows.pyc", line 15, in <module>
File "zipextimporter.pyc", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading _psutil_mswindows.pyd
I get this traceback when bundle_files = 3. zipfile may be specified or may be None, I still get the problem.
First, I thought this was a missing dll because of this page:
http://www.py2exe.org/index.cgi/ProblemsToBeFixed
I've copied all the dlls I found in Python27 into the same directory as the executable and added that directory path to os.environ['path']. That didn't worked.
Then I tried to import my package directly from site-packages.
I've replaced the whole sys.path of my compiled executable with my normal sys.path
sys.path = [r'C:\Python27\Lib\idlelib', ...]
I think the .pyd module got imported but Visual c++ threw me this really ugly error message:
Runtime Error!
Program: {path}.exe
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
I suggest you try to replace the whole sys.path to see if it is working. If it is, you could always make your single executable write the necessary module into a temp directory and add it to your path. If not, I feel like this problem is going to be hard to solve.

Categories