The script runs fine from pycharm but can't see my my lib
-> site-packages when ran as a shell script. I've set my PYTHONPATH variable and added it to path as %PYTHONPATH% but no luck. I've checked bashrc and can't see the environment variable being overwritten. Maybe my structure is incorrect?
-lib
- site-packages
-scripts
-src
- monroes_events.py
**Error:**
(venv) C:\Users\James\repos\web_scraper\src>bash web_scraper_setup.sh
python3 Monroes_Scraper.py
Traceback (most recent call last):
File "Monroes_Scraper.py", line 5, in <module>
import pandas as pd
ModuleNotFoundError: No module named 'pandas
Install pandas module using pip install pandas which is required to run the Monroes_Scraper.py
You can find more detail here
Related
I have created a package named as patterns along with test.py,
test.py has the following code lines:
from patterns.shapes import *
square()
[Module Error]
I have copied the test.py file to the same location F:, where I trying to run via command prompt.
To gain access to this package from any location I have installed it using pip install . in the windows command prompt, which was successful, but when I try to access the file test.py I am getting the error as below :
F:\>py test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
from patterns.shapes import *
ModuleNotFoundError: No module named 'patterns'
My package folder is stored in a different drive.
While working on a python project, one must always work in a virtual environment. Please check if you have your virtual environment activated. If not, then follow the steps:
cd your_working_directory
virtualenv environment_name where environment_name can be any name you want.
environment_name/Scripts/activate if on Windows
Or environment_name/bin/activate if on MacOS
Then after activating the environment you can install all the dependencies using pip. i.e pip install patterns
Python3 showing error while trying to create a new virtual environment from terminal using
virtualenv name_goes_here
with error,
Traceback (most recent call last):
File "/home/w3e/.local/bin/virtualenv", line 7, in
from virtualenv import main
ImportError: cannot import name 'main' from 'virtualenv' (/usr/lib/python3/dist-packages/virtualenv/init.py)
But it works when I do it from PyCharm > Settings > Project Interpreter > Add Python Interpreter
See the attached image below-
The command you were using doesn't exist.
Try this instead:
python3 -m venv your_venv
And activate it using:
source your_venv/Scripts/activate
I have a venv setup with Python 3.7 with several packages installed. I installed them using the UI in settings and the scripts run fine.
However, when I go to the Terminal window and try to run my script there there, it gives me an error message saying "No module named xxxx".
Running python3 run_glue.py, it curiously gives me the following error:
sh-3.2$ python3 run_glue.py
Traceback (most recent call last):
File "run_glue.py", line 27, in <module>
import torch
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/torch/__init__.py", line 79, in <module>
from torch._C import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/torch/_C.cpython-36m-darwin.so, 9): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/torch/lib/libshm.dylib
Reason: image not found
It seems that it is looking at a python 3.6 environment despite my virtual environment being 3.7. I checked my settings and I dont see why it would be looking at the python 3.6 environment.
Any thoughts here?
You need to activate your environment first:
sh-3.2$ source path_of_your_venv/bin/activate
You should now see an (env) before your bash prompt:
(env) sh-3.2$
Then you can check if python3 is correctly referencing the environment by which python3.
Alternatively, execute python3 directly from within your environment:
./path_of_your_venv/bin/python3 run_glue.py.
Every time that I need to run my python program with:
python my_program.py
I get some error saying that some import was not found.
Some error like this:
Traceback (most recent call last):
File "graphic.py", line 1, in <module>
import matplotlib.pyplot as plt
ImportError: No module named 'matplotlib'
Than I run:
sudo python my_program.py
And every thing works just fine. How do I remove the sudo command to run my python codes?
ImportError: No module named 'matplotlib' happens when your Python doesn't find the module. sudo changes the enviornment variables; That's why.
To fix this, locate where matplotlib is installed in your computer, and verify the folder is part of your sys.path.
import sys
sys.path
['C:\\Python27\\tests', ..., ...]
Then you've two options: insert that path from your script, i.e adding a line such import sys; sys.path.append(<folder>) or configure PYTHONPATH env variable under your user appending the folder to the path.
PYTHONPATH env variable gets loaded to sys.path on startup.
Best solution to me is a general workflow for all projects: use virtualenviroment]1.
sudo pip3 install virtualenv
virtualenv myenv
source mynenv/bin/activate
Then you should install your libraries again with pip and they will be installed in your virtualenviroment, isolated from everything else.
Every time I open terminal, at the very top I see this error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named virtualenvwrapper.hook_loader
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenv has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.
I tried reinstalling virtualenvwrapper as well as sudo rm -rf venv
Looks a whole lot like this (solved) question:
Python Virtualenv - No module named virtualenvwrapper.hook_loader
Does that help?