I am trying to make profanity_check run on a EC2 Linux instance.
The issue is that I get an ImportError: No module named profanity_check Error when I try to run profanity.py with python34 profanity.py.
Also, when try to run python profanity.py I get an ValueError: unsupported pickle protocol: 3 Error.
I assume this is because profanity_check only works with Python 3.
Furthermore I got an DEPRECATION: Python 2.7 will reach the end of its life warning when I installed profanity-check. However, I already have Python 3.4.9 installed on the system.
According to this issue here I already checked for the __init__.py file. It exists and looks stable.
The path to the __init__.py file is following:
/home/ec2-user/.local/lib/python2.7/site-packages/profanity_check/init.py
What could be the problem here?
profanity.py
#!/usr/bin/python34
from profanity_check import predict, predict_prob
predict(['predict() takes an array and returns a 1 for each string if it is offensive, else 0.'])
# [0]
__init__.py
from .profanity_check import predict, predict_prob
__version__="1.0.2"
You've installed profanity_check for Python 2.7
/home/ec2-user/.local/lib/python2.7/site-packages/profanity_check/__init__.py
But your script is run using Python 3.4
#!/usr/bin/python34 <-- this here
from profanity_check import predict, predict_prob
Change your script to use python2.7 or install profanity_check for python3.7
Related
I have a Colab notebook open and have my files cloned from a github repo. I want to run a python script called models.py. In this file, I am using pandas. When I run this line in Colab:
!python3 models.py
I get the following error:
Traceback (most recent call last):
File "models.py", line 1, in <module>
import pandas as pd
ModuleNotFoundError: No module named 'pandas'
However, if I run in a cell on Google Colab:
!pip3 list
I find that pandas is indeed installed:
pandas 0.25.3
My assumption is that when I run the script, it is not able to see the libraries I have installed but I am unsure how to fix this issue.
If I run:
!which python3
I get:
/usr/local/bin/python3
The python file I am trying to run is under:
/content/my_project/models.py
Should I instead take a different approach to running this file?
Instead of
!python3 models.py
You can use
%run models.py
In a clean Colab runtime, the location of python 3 is different than what you show in your question:
!which python3
# /usr/bin/python3
It looks like you are installing another Python instance in your VM. To ensure you're using Colab's bundled Python 3 executable, try using
!/usr/bin/python3 models.py
If you actually want to use the new python instance you've installed, you'll have to also install whatever packages you need. For example
!/usr/local/bin/python3 -m pip install pandas
I have a python file and the developer of that code has left the organization. When I run the code I get the following error.
import dataAnalysis as DV ModuleNotFoundError: No module named
'dataAnalysis'
I provide below the brief snippet of the python file "main.py" below.
import dataAnalysis as DV
def performCheck():
... other code
... other code
i = DV.addGraph( pathplus)
Here my question is , how to know the actual module or package name of "dataAnalysis" from the above import statement so that I can make "pip install ". However, I tried to install DataAnalysis module, still it does not work.
Is there any way to get the module or package name to install from the import statement in python ?
Go to console or terminal and run command pip install dataAnalysis. If permission denied, then make sure you have enough privilege to install a package.
Update:
In my opinion pip package DataAnalysis is a library that can be used for pre-processing a csv file. As per your given code, it looks like adding a graph so may be it could be a local package. Check dataAnalysis folder in your project with __init__.py file inside.
I recently tried to view Google Calendar using python . To do that I referred Python Quickstart. I did the steps that were mentioned in the website.
I completed the second step and downloaded the secretclient.json file.
In the terminal I typed in :
pip install --upgrade google-api-python-client
as I was instructed in the website.
I ran the python that was on the website and when I compiled I got the error:
Blockquote
Traceback (most recent call last):
File "quickstart.py", line 2, in
from apiclient import discovery
ModuleNotFoundError: No module named 'apiclient'
The Lines which correspond to the error are :
from apiclient import discovery
Why is the apiclient module unavailable ?
Could it be that you're using a different python version than what the pip installed? For example, if you use python3 to execute the problematic import line, but pip is for python2. Or if you use conda or another python distribution that uses a different path to import the packages from.
You can verify it if you just open from the command line:
python
then
from apiclient import discovery
and check if you still get the error.
you can resolve this by going to Script folder of your Python installation directory and running from there
e.g.
cd D:\Python27\Scripts\
python
from apiclient import discovery
Mainly this issue arises when u have more than one python installation , as noob have suggested
As part of my build system, I am using a modified version of a Python package (cogapp). I don't want to install the package because:
I've modified the package and don't want to worry about collision with unmodified versions which may already be installed.
It's nicer if the users of the build system don't need to install extra packages.
However, I'm having problems with using the package if it's not installed. If it is installed, I can run:
python -m cogapp <additional args>
and everything runs as intended.
The package has a __main__.py script:
import sys
from cogapp import Cog
sys.exit(Cog().main(sys.argv))
I tried running this directly, e.g.:
python -m <path>/__main__ <additional_args>
But I get the error:
...
/__main__.py", line 3, in <module>
from cogapp import Cog
ImportError: No module named cogapp
This is probably related to the error I get if I run __init__.py:
from .cogapp import *
The error is:
from .cogapp import *
ValueError: Attempted relative import in non-package
How can I run the package as a package?
EDIT:
I found a fix by removing all the relative imports from cogapp, and removing the -m, i.e. not running as a module. In this instance it's not too bad because it's a small package with only a single directory. However I'm interested in how this should be done in future. There's lots of stuff written around this subject, but no clear answers!
Here's the solution I've come to.
Disclaimer: you are actually installing the package but to a different path than the standard one.
$ mkdir newhome
$ python setup.py install --home=./newhome
$ PYTHONPATH=$PWD/newhome/lib/python <COMMAND_NEEDING_THAT_PACKAGE>
I need to import the multiprocessing module in Python 2.5.
I've followed the instructions here exactly: http://code.google.com/p/python-multiprocessing/wiki/Install
make and make test run without errors. I've also edited $PYTHONPATH to include the directory where the package is installed.
But 'import multiprocessing' still says: "ImportError: no module named multiprocessing".
What am I doing wrong? Is there some step missing from these instructions? I haven't installed a Python module before.
Navigate to the directory containing the package then type:
python setup.py install
This info was contained in the INSTALL.txt file.
http://code.google.com/p/python-multiprocessing/source/browse/trunk/INSTALL.txt
perhaps you can try:
import sys
sys.path.append('/path/to/processingdotpylibs/')
import processing