Trying to import Json, my command is pip install json.
I'm working on windows 8.1
The error i'm getting in command prompt is
Could not find a version that satisfies the requirements json <from versions:>
No matching distribution found for json.
and the error i'm getting on pycharm is
NameError: name 'json' is not defined
I tried importing numpy and it worked just fine .
I also did check Pip "Could not find a that satisfies the requirement"
and Could not find a version that satisfies the requirement <package>
Edit : Referred also to this link Python 3.5.1 : NameError: name 'json' is not defined and getting an error that sudo is not recognized
If it's not defined in your code, you need to import it. This is exactly the same as any name in Python; you can't use something until you have defined it.
import json
I have also encountered a similar issue, pip failing to install json and math modules (using python 3.x).
Finally, I discovered that some modules you simply do not have to install - they are already BUILT-IN. :)
Of course, you still have to add "import json" at the top of your .py file.
Hope this helps somebody.
Use the command as simplejson instead of json like below,
pip install simplejson
If the above command also throwing an error Use the following command
easy_install simplejson
easy_install works sometimes if pip cannot serve the request.
Related
I'm trying to import https://github.com/chrisconlan/algorithmic-trading-with-python in my code. I've never imported anything from GitHub before and have looked at various other questions that have been asked on Stack Overflow regarding this problem but it just doesn't work. When I try to run the 'portfolio.py' code for example I keep getting a ModuleNotFound error for 'pypm'. What exactly is the correct way to import such a module or the whole GitHub directory?
I'm working with Visual Studio Code on Windows.
You will need to pip install the module. In your case the command you would need to run is python -m pip install -U git+https://github.com/chrisconlan/algorithmic-trading-with-python. Once you have done that you need to find the name of the module. You can do this with pip list. Find the name of the module you just installed.
Then you just stick import <module name> at the top of your code with the rest of your imports.
What i used to do in this is to clone the repository on the folder where are installed the python's packages. This is useful when you do not want to use the pip cmd tool, keeping the pip's cache memory under control.
I am trying to get the download and upload speed in python by using the "speedtest" module, but it gives me that error when I use the module:
AttributeError: module 'speedtest' has no attribute 'Speedtest'.
and I was only declaring the variable,
that is my code :
import speedtest
speedtester = speedtest.Speedtest()
The module actually doesn't have the functions for some reason.
Please tell me what is wrong with my code I was sure to import the module from the cmd and also the pycharm terminal and still got the same error.
Thanks in advance
I had the same issue. I was using PyCharm IDE.
The issue occurs when you install speedtest using pip install speedtest
In order to solve the above mentioned issue, you need to use the following command.
pip install speedtest-cli
But before doing this, uninstall the previous one by using pip uninstall speedtest
Screenshot to installation
I was getting the same error. Then I google the problem and eventually came here. Later I realised that I have named my python file speedtest.py. I renamed it to something else (which is not the name of any python module) and it works just fine now.
<--Screenshot-->
So make sure this case.
If you installed "speedtest" and "speedtest-cli" libraries together then this issue will arise.
So first uninstall "speedtest" library using "pip uninstall speedtest" command.
Then try your code like :
"import speedtest
st = speedtest.Speedtest()
print(st.download()/1024)"
You will get output
i was also facing the same issue , what i have done is :
i have uninstall the speedtest and speedtest-cli
pip uninstall speedtest
pip uninstall speedtest-cli
then again install speedtest-cli
pip install speedtest-cli
The issue got solved after moving the speedtest.py file to the same directory as my script and it worked just fine. So just make sure the file is in the same folder as your python script.
Bumped into the issue and investigated the content of the module...
It appears what inside my venv folder I got a module folder "speedtest" with EMPTY init.py file and that is it...
Next to the folder was speedtest.py with actual code...
So deleting the empty folder/module helped me...
You should uninstall before speedtest whit the command 'pip uninstall speedtest' . After that, this use this code to find download and upload, speeds and ping:
import speedtest
test = speedtest.Speedtest()
print("Loading server list...")
test.get_servers()
print("Choosing best server...")
best = test.get_best_server()
print(f"Found: {best['host']} located in {best['country']}")
print("Performing download test...")
download_result = test.download()
print("Performing upload test...")
upload_result = test.upload()
ping_result = test.results.ping
print(f"Download speed: {download_result / 1024 / 1024:.2f}Mbit/s")
print(f"Upload speed: {upload_result / 1024 / 1024:.2f}Mbit/s")
print(f"Ping: {ping_result}ms")
I was facing the same problem,but main problem might be you are installing speedtest library which is not suitable instead use pip install speedtest-cli but before that remember to delete the previous one using pip uninstall speedtest and check the spelling of get_servers which is in the plural form
I've downloaded the XBRL module using pip install. But the Python interpreter says "No module named 'xbrl'", despite the XBRL being present via C:\Program Files\Python36\Lib\site-packages. How do I resolve this issue so I can run XBRL in Python?
I think you need to install python-xbrl.
Th easiest way is with pip :
pip install python-xbrl
Do you have two Pythons? It could be you installed the module with one pip/python and tried to import with another python.
Anyway there is nothing to use: the module xbrl.py doesn't have any content. This xbrl.py is unusable, you should look for a different implementation.
I have recently installed python 2.17.14 to use a package which I installed in the command prompt with:
python -m pip install packageName
However, whenever I try to use it with a script provided by the package authors, I get Import Errors:
ImportError: cannot import X from YX
ImportError: attempted relative import with no known parent package.
I don't know what I'm doing wrong, as I am really new to Python. Does anyone have any ideas?
The package is called neurodesign and I downloaded the try out script from the official website "neuropowertools.org"
Best,
Max
In case anyone (who is also new to python^^) fails ridiculously at this task as well: I had to manually install all the modules used within this package for it to work as they weren't installed automatically.
I am trying to download the Pygraphics module using Python 2.7.6 and have been heretofore unsuccessful. Below I detail the steps I have taken so far. Any help with this would be most appreciated.
First, I tried the typical install using pip
sudo pip install Pygraphics
When I try to import the module, I receive an error saying ImportError: No module named Pygraphics.
To test whether the module was installed I ran the following code: print sorted(["%s==%s" % (i.key, i.version) for i in pip.get_installed_distributions()]) which showed me all of my installed distributions.
This code returned the following list of all the distributions and clearly showed that Pygraphics is installed:
['altgraph==0.10.2', 'bdist-mpkg==0.5.0', 'bonjour-py==0.3', 'brewer2mpl==1.4', 'certifi==14.05.14', 'datetime==4.0.1', 'flask==0.10.1', 'ggplot==0.6.5', 'ipython==2.0.0-dev', 'itsdangerous==0.24', 'jdcal==1.0', 'jinja2==2.7.3', 'macholib==1.5.1', 'markupsafe==0.23', 'matplotlib==1.4.x', 'mock==1.0.1', 'modulegraph==0.10.4', 'nose==1.3.4', 'numpy==1.9.0.dev-297f54b', 'openpyxl==2.1.2', 'pandas==0.14.1', 'pandasql==0.6.1', 'patsy==0.3.0', 'pika==0.9.14', 'py2app==0.7.3', 'pygments==1.6', 'pygraphics==2.1']
After this, I tried using the GUI installer located on the following Pygrahpics install website. While going through the installer, I received an error message saying "PyGraphics requires System Python 2.7 to install" despite the fact that I have downloaded Python 2.7.6.
At this point I don't know what to do and was hoping someone who may have had a similar issue might be able to help me out.
Thank you for your time.
It looks like you've successfully install PyGraphics. Now import picture :)