While coding on python I faced a problem with importing modules using PIP. The thing is that I can not import a single module, for example "camelcase". Would someone help me?
import camelcase
c = camelcase.CamelCase()
txt = "hello world"
print(c.hump(txt))
It is expected that the output will be "Hello World". But there is following an error:
Traceback (most recent call last):
File "mycode.py", line 1, in
import camelcase
ModuleNotFoundError: No module named 'camelcase'
ModuleNotFoundError: No module named 'camelcase'.Error clearly said that you need to install camelcase package
official docs of camelcase package
virtual env set up
Use the following command:
pip install camelcase
import camelcase
c = camelcase.CamelCase()
txt = "hello world"
print(c.hump(txt))
Instead of third party package you can also do
print(txt.title())
Related
I am trying to learn how to use pymem in Python.
I have tried to make two different programs according to two tutorials I have seen but I always get the same error when I try to run the code.
I have this:
from pymem import Pymem
pm = pymem("ac_client.exe")
health = pm.read_int(0x007B43F4)
print ("Health: ", health)
But when I try to run the code I get the following error:
Traceback (most recent call last):
File "c:\Users\N\Desktop\PYTHON\pymem\pymem2.py", line 1, in <module>
from pymem import Pymem
File "c:\Users\N\Desktop\PYTHON\pymem\pymem.py", line 4, in <module>
from pymem.process import *
ModuleNotFoundError: No module named 'pymem.process'; 'pymem' is not a package
I have pymem installed in it's latest version from Visual Studio Code. And in the videos I've seen (one is from a few months ago) they have the same code as me.
You have a file named pymem.py that's mentioned in the exception message (specifically c:\Users\N\Desktop\PYTHON\pymem\pymem.py). This locally written pymem module is shadowing the pymem package you've installed elsewhere (python\python310\lib\site-packages according to one of your comments, though that path is not complete).
You need to rename your pymem.py file to something else if you want to be able to use the package.
I think you don't have it installed, try going into cmd, Terminal or whatever and type pip install pymem.
pip should install the package for you and you should be good.
I am using and importing ConfigParaser
import ConfigParser
config = ConfigParser.RawConfigParser()
config.read('Config.properties')
timeout_val=config.get('Section', 'commandtimeout')
and install it using,
pip install ConfigParser
While running the python script getting below mention error.
Traceback (most recent call last):
File "system_offline.py", line 41, in <module>
import ConfigParser
ImportError: No module named 'ConfigParser'
Now, my question is if run the same program using python 2.7 at the same system, above import statement works with out issue.
Wondering what needs to be done for this program to run with python3?
Edit: While using python 2.7 it is working but with python3, i am getting above mention error.
The ConfigParser module was renamed to configparser in Python 3.0.
If you are using python 3, this will work, the module was renamed
import configparser
config = configparser.RawConfigParser()
I am trying to import a pypi module (thinkx 1.1.2) into spyder. It is installed on anaconda and showing up on conda list. I my python path folders is my anaconda folder. When I attempt to import thinkx into spyder I get :
import thinkx
Traceback (most recent call last):
File "", line 1, in
import thinkx
ImportError: No module named 'thinkx'
According to module README, thinkx does not expose package named thinkx.
It provides the following modules:
thinkbayes: Code for Think Bayes.
thinkstats2: Code for Think Stats, 2nd edition
thinkbayes2: Code for Think Bayes, 2nd edition, not yet published.
thinkdsp: Code for Think DSP
thinkplot: Plotting code used in all of the books, mostly wrapper functions for matplotlib.pyplot
Try:
import thinkbayes
I need to make a portable app to put on a device and I want to put only the modules needed so there will not be all the standard modules so I need to see what my app needs, but if that module misses some imports I cannot see that, because it gives an error without being explicit what fails in that module:
Traceback (most recent call last):
File "./packaging.py", line 30, in <module>
import simplejson
ImportError: No module named simplejson
Is there a way to see what import exactly fails in that module?
The error means, that the import import simplejson fails because there is “[n]o module named simplejson”. The solution is to simply install said module.
It could be that the string /usr/lib/python2.7/dist-packages is not in your sys.path folder list so it's not being searched when attempts are made to import modules or packages.
you can catch the exceptions, to know what went wrong and handle them appropriately:
try:
import simplejson
except ImportError:
print "simplejson module not found"
#or do something else here, may be install that module
I'm a Python newbie, so bear with me :)
I created a file called test.py with the contents as follows:
test.py
import sys
print sys.platform
print 2 ** 100
I then ran import test.py file in the interpreter to follow an example in my book.
When I do this, I get the output with the import error on the end.
win32
1267650600228229401496703205376
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named py
Why do I get this error and how do I fix it? Thanks!
Instead of:
import test.py
simply write:
import test
This assumes test.py is in the same directory as the file that imports it.
This strange-looking error is a result of how Python imports modules.
Python sees:
import test.py
Python thinks (simplified a bit):
import module test.
search for a test.py in the module search paths
execute test.py (where you get your output)
import 'test' as name into current namespace
import test.py
search for file test/py.py
throw ImportError (no module named 'py') found.
Because python allows dotted module names, it just thinks you have a submodule named py within the test module, and tried to find that. It has no idea you're attempting to import a file.
You don't specify the extension when importing. Just do:
import test
As others have mentioned, you don't need to put the file extension in your import statement. Recommended reading is the Modules section of the Python Tutorial.
For a little more background into the error, the interpreter thinks you're trying to import a module named py from inside the test package, since the dot indicates encapsulation. Because no such module exists (and test isn't even a package!), it raises that error.
As indicated in the more in-depth documentation on the import statement it still executes all the statements in the test module before attempting to import the py module, which is why you get the values printed out.