I'm trying to run some tests in PyCharm using Behave and it keeps telling me I have this issue:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/bin/behave", line 7, in <module>
from behave.__main__ import main
ImportError: No module named behave.__main__
I had a colleague clone the project and they can run it fine on their machine, any insights?
Python 2.7.10
$ pip freeze | grep ehave
behave==1.2.5
The issue is that in Project Interpreter, I was using a different version of Python on my machine that did not have behave installed/included.
From Pycharm settings -> Project -> Python interpreter , search for behave and include it into your ptoject.
Related
I have my own project with virtual environment. When I am trying to debug code everything executes flawlessly and I get the expected output, but when I am trying to run it with run code option from Code Runner extension I receive the error:
[Running] python -u "c:\Users\slikm\Pulpit\ytapi\yt_api.py" Traceback (most recent call last): File "c:\Users\slikm\Pulpit\ytapi\yt_api.py", line 2, in <module> from googleapiclient.discovery import build ModuleNotFoundError: No module named 'googleapiclient'
I have the library which the module is taken from installed on my venv. I read that the problem might be with the interpreter the extension uses, but I don't really know how to figure it out.
I keep getting this error in VS Code:
Traceback (most recent call last):
File "c:\Users\User Name\Documents\Productivity\Coding\Python\Udemy\Projects from course\MilestoneP2\app.py", line 1, in <module>
import MilestoneP2.utils.Operations_db as Db
ModuleNotFoundError: No module named 'MilestoneP2'
I have recently shifted from Pycharm to VS Code and I am trying to open some of those projects from pycharm in VS Code but there is the above error haunting me.
PS: I have my Python Interpreter in a different directory and not in the workspace folder. It's in D:\Python\venv Drive
Here is my code:
import MilestoneP2.utils.Operations_db as Db
Here is the file hierarchy.
Anyone Help?
Thank you
If you run the script within VSCode there is a Python version button on bottom-left.
When you click on it you can specify your Python or virtual environment path. It will also try to find them automatically from directories. Then you can run your scripts with the spesified environments.
I found that when I run my scripts from environment - everything is OK.
But, when I try to run them from bash - I receive different errors with import modules. (ModuleNotFoundError, ImportError)
I didn't set the environment at all, so, please, tell me, what I should configure to succeed with it.
I use python 3.7
Received the next error:
Traceback (most recent call last):
File "main.py", line 1, in <module> from package_3.file3 import *
ModuleNotFoundError: No module named 'package_3'
The structure is:
package_1
file1.py
package_2
file2.py
package_3
file3.py
package_4
file4.py
What happens is, probably, that your working environment is python3, and when you run things in the shell, it's using python2. To solve it, run your script with python3 in the shell, as in:
python3 my_script.py
When calling a python script from within Pycharm my script runs successfully. However when I call the same script via my terminal I get an import error:
Macs-MacBook:src macuser$ python ./run_events.py
Traceback (most recent call last):
File "./run_events.py", line 3, in <module>
from functions import return_ga_data
File "/Users/macuser/PycharmProjects/ops-google-extract/src/functions.py", line 2, in <module>
import connect
File "/Users/macuser/PycharmProjects/ops-google-extract/src/connect.py", line 4, in <module>
from oauth2client.service_account import ServiceAccountCredentials
ImportError: cannot import name 'ServiceAccountCredentials'
I am not using an environment. Also I'm using python 3.7.
All my python scripts are in the same directory. My terminal's pwd is the same directory.
Tried:
Tried calling the script with python3 ./run_events.py but I get the same result.
Per an SO post about paths I added this to the top of connect.py:
import sys
sys.path.append('/Users/macuser/PycharmProjects/ops-google-extract/src/functions.py')
I still got the same result.
Why can I run the file without an import error from within my IDE but not via the terminal when using ./run_events.py?
Do you have python 2 installed as well? Type python --version in the terminal and see what you get? My guess is Pycharm might be configured to use python 3 while your default python in terminal is python 2, so your python 2 is lacking those modules that was installed for python 3. So when you execute your script in the terminal it's using python 2. If that's the case you can try,
py -3 ./myscript.py
I am currently experiencing problem with the virtual environment.
Using virtual environment wrapper, I used 'workon' to be in that environment. In this enviornment there is a Python 2.7 in Scripts folder and when I run python, it is indeed running this python.
When I run django-admin.py it returns the following error:
Traceback (most recent call last):
File "C:\Users\JOHN\Envs\courseva\Scripts\django-admin.py", line 2, in <module>
from django.core import management
ImportError: No module named django.core
FYI, I installed django and it is within this Envs/courseva folder (Lib/site-packages folder)
now. I was curious so I ran python and in the command I tried 'from django.core import management' and it is not throwing an error and I am really confused now.
I was concerned with the default Python 2.7 in C: so I even changed the environment path but no use. Please help.