I’m trying to install locally a personal package that I called circuits.
I installed it with pip install -e ., it shows up in the pip list, but I have a ModuleNotFoundError when I try to import it.
(venv) pip install -e .
Obtaining file:///Users/me/my_project/circuits
Installing build dependencies ... done
Checking if build backend supports build_editable ... done
Getting requirements to build editable ... done
Preparing editable metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in /Users/me/my_project/venv/lib/python3.9/site-packages (from circuits==0.1.0) (1.23.3)
Requirement already satisfied: tabulate in /Users/me/my_project/venv/lib/python3.9/site-packages (from circuits==0.1.0) (0.8.10)
Building wheels for collected packages: circuits
Building editable for circuits (pyproject.toml) ... done
Created wheel for circuits: filename=circuits-0.1.0-0.editable-py3-none-any.whl size=2277 sha256=a1ab6479e6d2761d7aae5cb156dd239001e54c397e712e279c6331b9ed217d0d
Stored in directory: /private/var/folders/mw/k72xg0bx6yz48vzqq4fbgsk80000gn/T/pip-ephem-wheel-cache-d5600og9/wheels/6d/ed/4d/6b97818bf8ea2c80312b9134aa990bb61b776a1399143dec7d
Successfully built circuits
Installing collected packages: circuits
Attempting uninstall: circuits
Found existing installation: circuits 0.1.0
Uninstalling circuits-0.1.0:
Successfully uninstalled circuits-0.1.0
Successfully installed circuits-0.1.0
(venv) cd ../projects
(venv) python -c "import circuits"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'circuits'
It turns out that the package is not added to my sys.path, although other packages that also are on my laptop are when I install them the same way.
I suspect that there may be some link with the fact that there already exists a package with the same name on pypi (https://pypi.org/project/circuits/)
which python returns /Users/me/my_project/venv/bin/python
which pip returns /Users/me/my_project/venv/bin/pip
Project directory structure:
.
├── README.md
├── build
│ └── bdist.macosx-12-arm64
├── circuits
│ ├── file_a.py
│ ├── file_b.py
│ └── file_c.py
├── circuits.egg-info
│ ├── PKG-INFO
│ ├── SOURCES.txt
│ ├── dependency_links.txt
│ ├── requires.txt
│ └── top_level.txt
├── pyproject.toml
├── setup.cfg
pyproject.toml content:
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
setup.cfg content:
[metadata]
name = circuits
version = 0.1.0
authors = ["me"]
[options]
packages = find:
install_requires =
numpy
I use MacOS 12.6
--
Edit 1: added precisions on the config and project tree, removed screenshot.
Try this
python -m pip install -e .
The outcome of pip install -e . is mostly based on project structure and on the content of package metadata files like setup.py, setup.cfg, pyproject.toml. These files are used to instruct pip how to install a Python package.
I suggest you to review how to build Python packages and how write the metadata files. Take a look here, it should give a basis: https://python-packaging-tutorial.readthedocs.io/en/latest/setup_py.html.
Another thing is that I see on the provided screenshot you install your package into its Virtual environment. I'm not sure if that's really what your need. In this case even if pip install -e . worked you'd only have access to your package from that venv, not from system Python installation.
If you just want to test your package interactively, just enter venv and run Python interpreter from the root project dir. Then you'll have access to own packages/modules and its dependencies installed to the venv.
Otherwise, if you need to install your package into system Python env, you need to pip install -e . outside of project's venv.
As #sinoroc pointed out in the comments, it was missing a __init__.py file in circuits
Related
I'm trying to spin up a super simple package for proof of concept and I can't see what i'm missing.
My aim is to be able to do the following:
python3 import mypackage
mypackage.add2(2)
>> 4
Github link
I created a public repo to reproduce the issue here
git clone https://github.com/OliverFarren/testPackage
Problem
I have a basic file structure as follows:
src/
mypackage/
__init__.py
mymodule.py
setup.cfg
setup.py
pyproject.toml
setup.cfg is pretty boiler plate from here
setup.py is just to allow pip install in editable mode:
import setuptools
setuptools.setup()
I ran the following commands at the top level directory in my Pycharm virtual env:
python3 -m pip install --upgrade build
python3 -m build
That created my dist and build directories and mypackage.egg-info file so now the directory looks like this:
testpackage
build/
bdist.linux-x86_64/
dist/
mypackage-0.1.0.tar.gz
mypackage-0.1.0-py3-none-any.whl
src/
mypackage/
mypackage.egg-info
__init__.py
mymodule.py
setup.cfg
setup.py
pyproject.toml
I've then tried install the package as follows:
sudo pip3 install -e .
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Installing collected packages: mypackage
Running setup.py develop for mypackage
Successfully installed mypackage
Which I think should have installed it. Except when I try and import the package I get a ModuleNotFoundError
I'm wondering whether this is a permissions issue of some sort. When I try:
sudo pip3 list
pip3 list
I notice i'm getting different outputs, I can see my package present in the list and in my sys.path:
~/testpackage/src/mypackage'
I just don't understand what i'm missing here. Any advice would be appreciated!
Ok so I found the issue. Posting solution and leaving the github repo live - with fix, incase anyone else has this issue.
It turns out my setup.cfg wasn't boiler plate.
Here was my incorrect code:
[metadata]
# replace with your username:
name = mypackage
author = Oliver Farren
version = 0.1.0
description = Test Package
classifiers =
Programming Language :: Python :: 3
License :: OSI Approved :: MIT License
Operating System :: OS Independent
[options]
package_dir =
= src/mypackage
packages = find:
python_requires = >=3.6
[options.packages.find]
where = src/mypackage
src/mypackage should be src, it was looking inside the package for packages.
A key step in debugging this issue was checking the mypackage.egg.info files. The SOURCES.txt contained a list of all the files in the build package and I could clearly see that in the incorrect build, that src/mypackage/mymodules.py and src/mypackage/__init__.py were missing. So the package was correctly installed by pip, but being empty was making for a very confusing error message.
I can't run pm2 on ubuntu box.
I'm not sure what's the problem.
The pm2 is installed globally.
npm list -g --depth=0
/opt/nodejs/lib
├── forever#0.15.3
├── node-gyp#3.4.0
├── npm#2.15.9
├── pm2#2.1.5
├── userdown#0.2.1
└── wait-for-mongo#0.2.0
But I still get
pm2
-bash: pm2: command not found
if I run other app
userdown
Starting Script is not provided
versions
node v4.5.0
npm v2.15.9
log from installation:
sudo npm install pm2 -g
npm WARN optional dep failed, continuing fsevents#1.0.15
/opt/nodejs/bin/pm2 -> /opt/nodejs/lib/node_modules/pm2/bin/pm2
/opt/nodejs/bin/rundev -> /opt/nodejs/lib/node_modules/pm2/bin/rundev
/opt/nodejs/bin/pm2-dev -> /opt/nodejs/lib/node_modules/pm2/bin/pm2-dev
/opt/nodejs/bin/pm2-docker -> /opt/nodejs/lib/node_modules/pm2/bin/pm2-docker
pm2#2.1.5 /opt/nodejs/lib/node_modules/pm2
├── gkt#1.0.0
├── eventemitter2#1.0.5
├── semver#5.3.0
├── async#1.5.2
├── fclone#1.0.10
├── pidusage#1.1.0
├── vizion#0.2.13
├── commander#2.9.0 (graceful-readlink#1.0.1)
├── debug#2.3.0 (ms#0.7.2)
├── pm2-axon-rpc#0.4.5 (fclone#1.0.8)
├── pm2-deploy#0.3.3 (tv4#1.2.7)
├── pm2-multimeter#0.1.2 (charm#0.1.2)
├── chalk#1.1.3 (escape-string-regexp#1.0.5, ansi-styles#2.2.1, supports-color#2.0.0, strip-ansi#3.0.1, has-ansi#2.0.0)
├── cli-table#0.3.1 (colors#1.0.3)
├── mkdirp#0.5.1 (minimist#0.0.8)
├── source-map-support#0.4.6 (source-map#0.5.6)
├── nssocket#0.6.0 (eventemitter2#0.4.14, lazy#1.0.11)
├── pmx#0.6.8 (json-stringify-safe#5.0.1)
├── pm2-axon#3.0.2 (amp-message#0.1.2, escape-regexp#0.0.1, amp#0.3.1, debug#2.2.0)
├── cron#1.1.1 (moment-timezone#0.5.9)
├── yamljs#0.2.8 (glob#7.1.1, argparse#1.0.9)
├── chokidar#1.6.1 (path-is-absolute#1.0.1, async-each#1.0.1, inherits#2.0.3, glob-parent#2.0.0, is-glob#2.0.1, is-binary-path#1.0.1, readdirp#2.1.0, anymatch#1.3.0)
├── shelljs#0.7.5 (interpret#1.0.1, glob#7.1.1, rechoir#0.6.2)
└── moment#2.17.0
kamil#vps2:~$ pm2
-bash: pm2: command not found
ubuntu version:
uname -a
Linux vps2 2.6.32-042stab111.11 #1 SMP Tue Sep 1 18:19:12 MSK 2015 x86_64 x86_64 x86_64 GNU/Linux
Ok got answer myself.
I check what happens for
whereis pm2
pm2: /opt/nodejs/bin/pm2
then I checked
whereis userdown
userdown: /usr/bin/userdown /usr/bin/X11/userdown /opt/nodejs/bin/userdown
hmm in /usr/bin....
So I did
sudo ln -s /opt/nodejs/bin/pm2 /usr/bin/pm2
and it works :)
The problem is that you are running NPM as sudo, so you will only be able to access it using:
sudo pm2 start server.js
Install without sudo, you may even install without the -gflag and call it directly from node_modules directory. This may be useful if you do not have root (admin) privileges in the machine you're working on.
npm install pm2
./node_modules/.bin/pm2 start server.js
Follow the proper nodejs isntallation, npm permission fixes and npm global packages tweaks:
# https://gist.github.com/servercharlie/9a7e0d0e1645b4c6fbfe5de566fcf1ca
Your script needs to do some thing that requires root privilege? (ie: you're getting an error on using port 80)
[wrong] - trying to run w/ sudo
[correct] - login as root "sudo su" then do pm2 start app.js --name "whatever" --watch
that does it, no need to configure any bashrc or profile files.
extra: worried about your app doing crazy shit? (ie, since it's executed as root, the script can use nodejs's exec and do some crazy stuff.)
hence. do this: do the root-stuff first with your script, then lower your privilege after some timeout:
// i use port 80 first.. at this point the script's uid is ROOT.
app.listen(80);
// after 2 seconds we switch to uid AZUREUSER, which obviously isn't root anymore.
setTimeout(function(){
process.setuid("azureuser");
}, 2000);
In my scenario I wrote a shell script that was triggered by jenkins build and
I fixed using following link
https://github.com/Unitech/pm2-deploy/issues/41
I'm running into a problem with accessing Yeoman after installing it on a fresh Homestead installation. Everything seems fine during the install after npm install -g yo and yo doctor runs just fine and finds no problem during the installation. However, after I've installed yeoman, yo: command not found is the error message I'm getting on my VM.
vagrant#homestead:~$ npm install -g yo
npm WARN deprecated npmconf#2.1.2: this package has been reintegrated into npm and is now out of date with respect to npm
/home/vagrant/.node/bin/yo -> /home/vagrant/.node/lib/node_modules/yo/lib/cli.js
/home/vagrant/.node/bin/yo-complete -> /home/vagrant/.node/lib/node_modules/yo/lib/completion/index.js
> spawn-sync#1.0.15 postinstall /home/vagrant/.node/lib/node_modules/yo/node_modules/spawn-sync
> node postinstall
> yo#1.8.4 postinstall /home/vagrant/.node/lib/node_modules/yo
> yodoctor
Yeoman Doctor
Running sanity checks on your system
✔ Global configuration file is valid
✔ Node.js version
✔ No .bowerrc file in home directory
✔ No .yo-rc.json file in home directory
✔ npm version
✔ NODE_PATH matches the npm root
Everything looks all right!
/home/vagrant/.node/lib
└─┬ yo#1.8.4
├── async#1.5.2
├─┬ chalk#1.1.3
│ ├── ansi-styles#2.2.1
│ ├── escape-string-regexp#1.0.5
│ ├── has-ansi#2.0.0
│ ├── strip-ansi#3.0.1
│ └── supports-color#2.0.0
├── cli-list#0.1.8
[[REMOVED FOR READABILITY]]
└─┬ yosay#1.2.0
├── cli-boxes#1.0.0
├── pad-component#0.0.1
├─┬ taketalk#1.0.0
│ ├── get-stdin#4.0.1
│ └── minimist#1.2.0
└── wrap-ansi#2.0.0
vagrant#homestead:~$ yo
yo: command not found
My path in ~/.bashrc says the following: PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/home/vagrant/.node/lib
Is there anything else that I'm missing here that might be causing this?
Add /home/vagrant/.node/bin to your path. :)
There's a problem with installing my global modules properly.
My System
OS: OS X Mountain Lion
node.js: 0.10.18 (Package installer)
Steps to reproduce
Input
npm install coffee -g (or any other module)
Output
npm http GET https://registry.npmjs.org/coffee
npm http 200 https://registry.npmjs.org/coffee
{lots of dependencies}
coffee#0.0.1 /usr/local/lib/node_modules/coffee
├── node-getopt#0.2.3
├── modular-amd#0.1.2
├── chai#1.7.2 (assertion-error#1.0.0)
├── mocha#1.11.0 (growl#1.7.0, debug#0.7.2, commander#0.6.1, diff#1.0.2, mkdirp#0.3.5, ms#0.3.0, jade#0.26.3, glob#3.2.1)
├── express#3.2.6 (methods#0.0.1, fresh#0.1.0, range-parser#0.0.4, cookie-signature#1.0.1, buffer-crc32#0.2.1, cookie#0.1.0, debug#0.7.2, commander#0.6.1, mkdirp#0.3.4, send#0.1.0, connect#2.7.11)
├── sinon#1.7.3 (buster-format#0.5.6)
└── sinon-chai#2.4.0
Input
coffee
Output
-bash: coffee: command not found
Other information
npm config get prefix: /usr/local
Read/Write access für /usr/local: Yes
$PATH: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
/usr/local/share/npm exists: No
/usr/local/lib/node_modules/coffee exists: Yes
/usr/local/bin/coffee exists: No
What else can I do?
I won't add the direct link to coffee to my $PATH-variable, because that's not my job, that's the job of npm! Really, why should I use npm when I could do it by myself? I read that answer like 100 times and I have no words for this, which aren't against the rules on SO.
If you want to install CoffeeScript globally (as one of the tags suggests), you shall install coffee-script (not coffee).
Additionally, sudo is required for installing global module on the Mac.
Command:
sudo npm install coffee-script -g
Input
% coffee
Output
coffee>
I used node.js to install karma. My first try failed when running the following command on Terminal:
npm install -g karma
That failed so I decided to use:
sudo npm install -g karma
After entering my password it seemed to install correctly.
I am pasting part of the output of the install, maybe it will mean something to someone and it will be relevant to my question. After all the npm http messages this is what I see:
> ws#0.4.27 install /usr/local/share/npm/lib/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)
CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
SOLINK_MODULE(target) Release/bufferutil.node
SOLINK_MODULE(target) Release/bufferutil.node: Finished
CXX(target) Release/obj.target/validation/src/validation.o
SOLINK_MODULE(target) Release/validation.node
SOLINK_MODULE(target) Release/validation.node: Finished
/usr/local/share/npm/bin/karma -> /usr/local/share/npm/lib/node_modules/karma/bin/karma
karma#0.8.6 /usr/local/share/npm/lib/node_modules/karma
├── pause#0.0.1
├── dateformat#1.0.2-1.2.3
├── xmlbuilder#0.4.2
├── colors#0.6.0-1
├── chokidar#0.6.2
├── growly#1.1.1
├── mime#1.2.9
├── q#0.9.6
├── rimraf#2.1.4 (graceful-fs#1.2.3)
├── coffee-script#1.6.3
├── minimatch#0.2.12 (sigmund#1.0.0, lru-cache#2.3.0)
├── optimist#0.3.5 (wordwrap#0.0.2)
├── glob#3.1.21 (inherits#1.0.0, graceful-fs#1.2.3)
├── LiveScript#1.0.1 (prelude-ls#1.0.1)
├── log4js#0.6.6 (dequeue#1.0.3, semver#1.1.4, async#0.1.15, readable-stream#1.0.2)
├── lodash#1.1.1
├── http-proxy#0.10.3 (pkginfo#0.2.3, utile#0.1.7)
├── istanbul#0.1.22 (abbrev#1.0.4, which#1.0.5, fileset#0.1.5, nopt#2.0.0, wordwrap#0.0.2, async#0.1.22, mkdirp#0.3.5, esprima#0.9.9, escodegen#0.0.24, handlebars#1.0.12)
└── socket.io#0.9.16 (base64id#0.1.0, policyfile#0.0.4, redis#0.7.3, socket.io-client#0.9.16)
Then when I try to run the following command to create a karma config file with this command:
karma init karma.config.js
this is the message that gets returned:
-bash: karma: command not found
I have tried the same command with sudo before it but I get the same result.
Does anyone have any idea as to what is going on?
Any help is appreciated.
*Update!
I decided to check a file named: builderror.log
located in: /usr/local/share/npm/lib/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
This is what it shows:
gyp WARN EACCES user "root" does not have permission to access the dev dir "/Users/eperez/.node-gyp/0.10.5"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/share/npm/lib/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws/.node-gyp"
gyp http GET http://nodejs.org/dist/v0.10.5/node-v0.10.5.tar.gz
gyp http 200 http://nodejs.org/dist/v0.10.5/node-v0.10.5.tar.gz
#mayankcpdixit gave the answer up there in a response to the OP's original question, but I'll put it here again in case anyone misses it.
You do not need to uninstall everything, and if I had to manually add a new path link for every npm package I try to install I'd probably shoot myself.
npm install -g karma-cli
Boom. Now you have karma command lines installed. Just like Grunt.
Edit: Please don't forget to upvote #mayankcpdixit as well, he commented directly on the original post, but didn't actually "answer" the question.
In your ~/.bash_profile (or similar) amend your PATH to include npm-installed binaries:
export PATH="$PATH:/usr/local/share/npm/bin"
I had this very same issue, and found this solution to be less time-consuming and impactful than completely re-installing node.
EDIT this has also worked for others in bash_profile
export PATH="$PATH:/usr/local/lib/node_modules/karma/bin"
It is recommended to install karma with its Command-Line-Interface (karma-cli) which will take care of fetching the appropriate karma. You can also install a different local version specific to each project you're working on and karma-cli will pick the appropriate one.
From the karma installation page:
Typing ./node_modules/karma/bin/karma start sucks so you might find it useful to install karma-cli globally:
npm install -g karma-cli
Now, check that karma was installed by typing:
karma start
You can also check that karma was installed by going to this directory:
cd /usr/local/lib/node_modules/karma
Good luck!
Don't need to completely uninstall node.js
Just
sudo rm -rf /usr/local/lib/node_modules/npm/
Then
install node.js
Then
reinstall karma
This worked for me.
I had to add export PATH="$PATH":/usr/local/lib/node_modules/npm/node_modules/karma/bin after installing karma with sudo npm install karma.
hope this helps.
Just go to test.sh:
Find: $BASE_DIR/../node_modules/karma/bin/karma start $BASE_DIR/../config/karma.conf.js $*
Replace with: /usr/local/bin/karma start $BASE_DIR/../config/karma.conf.js $*
Or: karma start $BASE_DIR/../config/karma.conf.js $*
I was also facing the same issue. It looks like karma for command line is a separate package which can be installed by
npm install -g karma-cli
When upgrading from Karma 0.10 to 0.12 the link to the karma executable is removed.
You can get it back with
cd node_modules/.bin
ln -s ../karma/bin/karma karma
Try re-installing node.js. There are lots of ways to install it, but I recommend downloading from nodejs.org
If that doesn't work, you may try to re-install karma.